TStatusBar 与底部对齐面板

发布于 2024-12-23 02:33:11 字数 688 浏览 2 评论 0原文

我有一个带有 TStatusBar 和底部对齐的 TPanel、底部对齐的 TSplitter 和客户端对齐的 TPanel 的表单,如下面的截图所示:

Screen Shot 1 - Before - Good

(分离器被涂成红色,使其更显眼一些)显而易见)

Button1 只是增加了Panel1 的高度增加 20:

Panel1.Height := Panel1.Height + 20;

但是当单击时,控件的顺序会发生变化,Panel1 会超出状态栏,并且拆分器现在会调整状态栏的大小。

Screen Shot 2 - After - Bad

仅当 Panel1 的高度增加超过 StatusBar1 的高度 (19 )。

我认为这是由两个底部对齐的控件引起的,但我不知道问题的确切原因以及如何解决它。

我目前使用的是XE2,但D2010也有同样的问题。

在这种情况下,有没有办法将 Panel1 的高度设置为任意值,同时确保控件保持其预期位置?

I have a form with a TStatusBar, and bottom aligned TPanel, a bottom aligned TSplitter and client aligned TPanel, as shown in the following screenshot:

Screen Shot 1 - Before - Good

(The splitter is coloured red to make it a little more obvious)

Button1 simply increases the height of Panel1 by 20:

Panel1.Height := Panel1.Height + 20;

But when clicked the order of the controls changes, with Panel1 being blow the status bar and the splitter is now resizing the status bar.

Screen Shot 2 - After - Bad

This only happens when the height of Panel1 is increased by more than the height of StatusBar1 (19).

I assume this is caused by having two bottom aligned controls, but I'm at a loss as to the exact cause of the problem and how to work around it.

I'm currently using XE2, but I have the same issue with D2010.

In this situation is there a way to set the height of Panel1 to an arbitrary value, while ensuring that the controls maintain their expected positions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小糖芽 2024-12-30 02:33:12

通过在更改面板高度后设置控件的 Top 属性来解决此问题。

StatusBar1.Top := Panel1.Top + Panel1.Height;

Work around the problem by setting the Top property for the controls after changing the panel height.

StatusBar1.Top := Panel1.Top + Panel1.Height;
叫思念不要吵 2024-12-30 02:33:12

试试这个(对我来说效果很好):

procedure TForm1.Button1Click(Sender: TObject);
begin
  Panel1.SetBounds(Panel1.Left, Panel1.Top - 20,
                   Panel1.Width, Panel1.Height + 20);
end;

Try this (worked fine for me):

procedure TForm1.Button1Click(Sender: TObject);
begin
  Panel1.SetBounds(Panel1.Left, Panel1.Top - 20,
                   Panel1.Width, Panel1.Height + 20);
end;
血之狂魔 2024-12-30 02:33:12

或者,如果您不想跟踪更改控件位置/大小的位置,

type
  TForm1 = class(TForm)
    ..
  private
  protected
    procedure AlignControls(AControl: TControl; var Rect: TRect); override;

..

procedure TForm1.AlignControls(AControl: TControl; var Rect: TRect);
begin
  inherited;
  if AControl = Panel1 then
    StatusBar1.Top := Panel1.Top + Panel1.Height;
end;

Alternatively, if you don't want to keep track of where you're changing position/size of controls,

type
  TForm1 = class(TForm)
    ..
  private
  protected
    procedure AlignControls(AControl: TControl; var Rect: TRect); override;

..

procedure TForm1.AlignControls(AControl: TControl; var Rect: TRect);
begin
  inherited;
  if AControl = Panel1 then
    StatusBar1.Top := Panel1.Top + Panel1.Height;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文