How to auto resize and adjust Form controls with c

2020-01-27 00:29发布

I have noticed that some applications change their controls position to adjust them as much as possible in the resolution as possible, If window is maximized they set themselves in such a way that over all GUI looks balanced. My question is that is it possible to make or implement this functionality in Visual studio 2010 C#?

9条回答
一纸荒年 Trace。
2楼-- · 2020-01-27 00:52

in the form load event add this line

this.WindowState = FormWindowState.Maximized;
查看更多
趁早两清
3楼-- · 2020-01-27 00:54

Use Dock and Anchor properties. Here is a good article. Note that these will handle changes when maximizing/minimizing. That is a little different that if the screen resolution changes, but it will be along the same idea.

查看更多
Ridiculous、
4楼-- · 2020-01-27 00:56
float widthRatio = Screen.PrimaryScreen.Bounds.Width / 1280;
float heightRatio = Screen.PrimaryScreen.Bounds.Height / 800f;
SizeF scale = new SizeF(widthRatio, heightRatio);
this.Scale(scale);
foreach (Control control in this.Controls)
{
control.Font = new Font("Verdana", control.Font.SizeInPoints * heightRatio * widthRatio);
}
查看更多
登录 后发表回答