在窗体调整大小或最大化时重新放置控件 [英] repositioning a controll when form resizes or maximised
本文介绍了在窗体调整大小或最大化时重新放置控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当表单调整大小或最大化时,我想重新放置控件.代码是什么.
例如,我在窗体的右下角放置了一个命令按钮.如果表单最大化或调整大小,则命令按钮将位于相同位置.
私有 void fMain_Resize(对象发件人,EventArgs e)
{
button1.Location = 新点(( int )((< float ) this .Location.X * 0 . int )((< this .Location.Y * 8 )));
}
有关如何解决不同屏幕分辨率的问题,请参见我的旧答案: ^ ].表单大小不同的问题需要完全相同的方法.
我还需要添加:使用属性MinimumSize
和MaximumSize
:这也是UI布局鲁棒性的关键.
另请参见: GUI外观-C#.Net [ 解决方案
this alwais positon button at 80% of form widht and 80 % of form Height :
private void fMain_Resize(object sender, EventArgs e) { button1.Location = new Point((int)((float)this.Location.X * 0.8), (int)((float)this.Location.Y * 0.8)); }
See my old Answer on how to solve the problem different screen resolutions: Zom Out malfunctions when Screen resolution changes[^]. A problem of different form sizes require exact same approach.
I also need to add: Use propertiesMinimumSize
andMaximumSize
: it''s also a critical thing to UI layout robustness.
See also: GUI Apperance - C#.Net[^].
—SA
这篇关于在窗体调整大小或最大化时重新放置控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文