gpt4 book ai didi

delphi - 使用拆分器时如何保持控件在表单中可见?

转载 作者:行者123 更新时间:2023-12-03 15:07:32 24 4
gpt4 key购买 nike

在表单上,​​我有两个大控件和它们之间的 TSplitter。顶部的控件与顶部对齐,底部的控件与客户端对齐。因此,当我调整窗体大小时,顶部的控件保持相同的高度,而底部的控件则不同。然后它们之间的分离器实质上控制了顶部控件的高度。

但是,当窗体大小调整为小于顶部控件的高度时,底部控件将被隐藏。我尝试使用约束来调整其 react 方式,但没有运气......

  • 调整拆分器大小时,不应允许用户将其向下拖动到超过底部控件的最小高度
  • 当窗体大小调整得小于底部控件允许的大小时,它应该自动调整顶部控件的高度以适应底部控件
  • 当我将底部控件的 MinHeight 约束设置为(例如)100 时,在调整拆分器大小时,它会使表单实际增长以适合底部控件,而不是阻止用户调整任何大小进一步。
  • 当我将拆分器的 MinSize 属性设置为(例如)100 时,在调整拆分器大小时,我会得到非常异常的结果(顶部控件消失),并且仍然隐藏底部控件。

当拆分器或表单调整大小时,如何确保底部控件始终可见,不改变表单的大小?

DFM 代码:

object Form1: TForm1
Left = 310
Top = 121
Caption = 'Form1'
ClientHeight = 374
ClientWidth = 434
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Splitter1: TSplitter
Left = 0
Top = 129
Width = 434
Height = 7
Cursor = crVSplit
Align = alTop
Beveled = True
end
object Panel1: TPanel
Left = 0
Top = 0
Width = 434
Height = 129
Align = alTop
Caption = 'Panel1'
TabOrder = 0
ExplicitLeft = 48
ExplicitTop = 16
ExplicitWidth = 313
end
object Panel2: TPanel
Left = 0
Top = 136
Width = 434
Height = 238
Align = alClient
Caption = 'Panel2'
TabOrder = 1
ExplicitLeft = 16
ExplicitTop = 168
ExplicitWidth = 369
ExplicitHeight = 145
end
end

最佳答案

When the splitter is resized, it shouldn't allow the user to drag it down any further than the bottom control's min height

为拆分器的 OnCanResize 添加处理程序,以防止将其向下拖动到超过预定义高度:

procedure TForm1.Splitter1CanResize(Sender: TObject; var NewSize: Integer;
var Accept: Boolean);
begin
Accept := NewSize <=
ClientHeight - (100 + Splitter1.Height);
end;

(100是预定义的高度,用常量/属性替换它们...)


When the form is resized smaller than the bottom control allows, it should automatically resize the top control's height to allow the bottom control to fit

首先,您最好对表单进行约束,以使所有控件始终具有正高度。否则,您可能会遇到对齐竞争问题:panel1 和 splitter1 在顶部对齐:

procedure TForm1.FormCreate(Sender: TObject);
begin
Constraints.MinHeight := Height - ClientHeight + 100 + Splitter1.Height + 1;
end;

其次,您可以检查表单大小调整是否导致底部面板的大小调整得小于应有的大小,并采取纠正措施:

procedure TForm1.FormResize(Sender: TObject);
begin
if Panel2.Height < 100 then
Panel1.Height := ClientHeight - (100 + Splitter1.Height);
end;


When I set the bottom control's MinHeight constraint to, for example, 100, when resizing the splitter, it makes the form actually grow to fit the bottom control, rather than stopping the user from sizing any further.

不要使用底部面板的约束。


When I set the splitter's MinSize property to, for example, 100, when resizing the splitter, I get very abnormal results (top control disappearing) and still hides the bottom control.

不要使用分割器的MinSize

关于delphi - 使用拆分器时如何保持控件在表单中可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24520830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com