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条回答
男人必须洒脱
2楼-- · 2020-01-27 00:34

Here I like to use https://www.netresize.net/index.php?c=3a&id=11#buyopt. But it is paid version.

You also can get their source codes if you buy 1 Site License (Unlimited Developers).

How ever I am finding the nuget package solution.

查看更多
太酷不给撩
3楼-- · 2020-01-27 00:38

Use combinations of these to get the desired result:

  1. Set Anchor property to None, the controls will not be resized, they only shift their position.

  2. Set Anchor property to Top+Bottom+Left+Right, the controls will be resized but they don't change their position.

  3. Set the Minimum Size of the form to a proper value.

  4. Set Dock property.

  5. Use Form Resize event to change whatever you want

I don't know how font size (label, textbox, combobox, etc.) will be affected in (1) - (4), but it can be controlled in (5).

查看更多
成全新的幸福
4楼-- · 2020-01-27 00:46

..and to detect a change in resolution to handle it (once you're using Docking and Anchoring like SwDevMan81 suggested) use the SystemEvents.DisplaySettingsChanged event in Microsoft.Win32.

查看更多
Luminary・发光体
5楼-- · 2020-01-27 00:46
private void MainForm_Load( object sender, EventArgs e ) 
     { 
        this.Size = Screen.PrimaryScreen.WorkingArea.Size 
     }
查看更多
SAY GOODBYE
6楼-- · 2020-01-27 00:47

add this code at page load do for all control or add all control in containers

int x;
Point pt = new Point();
x = Screen.PrimaryScreen.WorkingArea.Width - 1024;
x = x / 2;
pt.Y = groupBox1.Location.Y + 50;
pt.X = groupBox1.Location.X + x;
groupBox1.Location = pt;
查看更多
Juvenile、少年°
7楼-- · 2020-01-27 00:47
this.WindowState = FormWindowState.Maximized;
查看更多
登录 后发表回答