TPanel在包含TPanel时不会使用AutoSize [英] TPanel does not AutoSize when containing a TPanel

查看:500
本文介绍了TPanel在包含TPanel时不会使用AutoSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有另一个面板:





内部面板对齐 alTop





外面板设置为 AutoSize = true





尺寸。如果我在设计时更改内部面板的高度,则外部面板自动调整大小以适应它:





现在运行时



现在我需要。



有什么修正?



解决方法当然是绕过对齐 / 自动调整,并在各种 OnResize 事件中执行所有操作。但这显然不是RAD。我确定这是VCL的一个小bug。而且由于我们已经有了十二个XE6 VCL错误,我们修补了,最好是修复它,所以没有人必须考虑。



奖金Chatter



我喜欢这行:


项目?


几乎好像没有人打扰甚至尝试重现它。

解决方案

问题是在 TWinControl.AlignControls 中的回归:

  procedure TWinControl.AlignControls(AControl:TControl; var Rect:TRect); 
begin
//...snip

//应用任何约束
如果显示和((FScalingFlags中的(sfWidth))或(sFHeight在FScalingFlags中))然后
DoAdjustSize;

//...snip
end;

这里的错误是它不会调用 DoAdjustSize ,除非存在 sfWidth sfHeight 缩放标志。



修复是不要试图超越自己,而 DoAdjustSize 不管:

  procedure TWinControl.AlignControls(AControl:TControl; var Rect:TRect); 
begin
//...snip

//应用任何约束
// QC125995:不要缩放标志来决定是否调整大小
如果显示{和((ffalingFlags中的sfWidth)或(fFlagsFlags中的sfHeight))然后
DoAdjustSize;

//...snip
end;

找到此修复程序,我们中途解决类似的问题除了 TOleControl (例如 TWebBrowser )而不是 TPanel


注意:任何代码发布到公共领域。不需要归属。



I have a panel inside another:

The inner panel is aligned alTop:

And the outer panel is set to AutoSize=true:

And everything sizes. If i changes the height of the inner panel at design time, the outer panel auto sizes to accommodate it:

And now runtime

Now i need to change the height of the inner panel at runtime:

procedure TForm2.Button1Click(Sender: TObject);
begin
    pnlInner.Height := pnlInner.Height + 50;
    lblPointer.Top := pnlOuter.Top + pnlInner.Height;
end;

Except when i change the height of the inner panel at runtime, the autosize panel does not autosize:

This of course worked in Delphi 5, 7, and probably XE2 - XE5.

What's the fix?

The workaround is, of course, to bypass Alignment/Autosize and do everything during various OnResize events. But that's distinctly not RAD. I'm sure it's a small bug in the VCL somewhere. And since we already have about two-dozen XE6 VCL bugs that we've patched, it would be better to fix it so nobody else has to think about it.

Bonus Chatter

I love the line:

and, could you please attach sample project?

It's almost as if nobody bothered to even try to reproduce it.

解决方案

The issue is a regression in TWinControl.AlignControls:

procedure TWinControl.AlignControls(AControl: TControl; var Rect: TRect);
begin
   //...snip

   // Apply any constraints
   if Showing and ((sfWidth in FScalingFlags) or (sfHeight in FScalingFlags)) then
      DoAdjustSize;

   //...snip
end;

The bug here is that it will not call DoAdjustSize unless either sfWidth or sfHeight scaling flags are present.

The fix is to not try to outsmart yourself, and DoAdjustSize regardless:

procedure TWinControl.AlignControls(AControl: TControl; var Rect: TRect);
begin
   //...snip

   // Apply any constraints
   //QC125995: Don't look to scaling flags to decide if we should adjust size
   if Showing {and ((sfWidth in FScalingFlags) or (sfHeight in FScalingFlags))} then
      DoAdjustSize;

   //...snip
end;

With this fix found, we're halfway to solving the similar issue except with a TOleControl (e.g. TWebBrowser) rather than a TPanel.

Note: Any code released into public domain. No attribution required.

这篇关于TPanel在包含TPanel时不会使用AutoSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆