【发布时间】:2011-07-19 23:31:04
【问题描述】:
在更改控件大小后,我正在重置从 OnLayout 处理程序中的 Panel 派生的控件中的表单大小。
panel->ClientSize = size;
this->Parent->ClientSize =
System::Drawing::Size(
this->Parent->ClientSize.Width,
this->Parent->ClientSize.Height-difference);
使用调试器单步执行代码表明位置的变化发生在表单的 ClientSize 发生变化时。 面板未固定在表单上。
我遇到的问题是这会导致控件位置发生变化。
>>> FormPanel::layoutPanel - {X=604,Y=0}{Width=766, Height=250}
FormPanel::layoutPanel Height set - {X=604,Y=0}{Width=766, Height=217}
FormPanel - OnSizeChanged:{X=604,Y=0}{Width=766, Height=217}
FormPanel - OnLocationChanged:{X=604,Y=-17}{Width=766, Height=217}
FormPanel - OnMove:{X=604,Y=-17}{Width=766, Height=217}
Setting Form1->ClientSize = {Width=1370, Height=217}
<<< FormPanel::layoutPanel - {X=604,Y=-17}{Width=766, Height=217}
我得到两个事件,并且控件已移动到 Y = -17。
我的问题是:
1) OnLocationChanged 和 OnMove 有什么区别?
2) 为什么它移动了?
3) 我在这里做错了吗?
【问题讨论】:
-
LayoutEngine 不会期望子控件更改其父控件,您在那儿有点自己。
-
它不需要移动控件。
-
嗯,我想我明白你的意思了。有各种奇怪的效果。出发去发明 B 计划。
标签: .net c++ winforms visual-studio-2010