在窗体调整大小或最大化时重新放置控件 [英] repositioning a controll when form resizes or maximised

查看:95
本文介绍了在窗体调整大小或最大化时重新放置控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当表单调整大小或最大化时,我想重新放置控件.代码是什么.

例如,我在窗体的右下角放置了一个命令按钮.如果表单最大化或调整大小,则命令按钮将位于相同位置.

 私有  void  fMain_Resize(对象发​​件人,EventArgs e)
{
    button1.Location = 点(( int )((< float ) this  .Location.X *  0 . int )((< this  .Location.Y *  8 )));
} 


有关如何解决不同屏幕分辨率的问题,请参见我的旧答案: 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 properties MinimumSize and MaximumSize: it''s also a critical thing to UI layout robustness.

See also: GUI Apperance - C#.Net[^].

—SA


这篇关于在窗体调整大小或最大化时重新放置控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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