Take the 2-minute tour ×

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#?

share|improve this question

8 Answers 8

up vote 26 down vote accepted

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.

share|improve this answer
The article link is dead. –  c00000fd Oct 26 '13 at 4:04
@c00000fd - The link has been reinstated –  SwDevMan81 Nov 12 '13 at 16:02
float widthRatio = Screen.PrimaryScreen.Bounds.Width / 1280;
float heightRatio = Screen.PrimaryScreen.Bounds.Height / 800f;
SizeF scale = new SizeF(widthRatio, heightRatio);
foreach (Control control in this.Controls)
control.Font = new Font("Verdana", control.Font.SizeInPoints * heightRatio * widthRatio);
share|improve this answer
thanks but the accepted answer is way more elegant than this –  Afnan Bashir Sep 16 '12 at 9:20

..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.

share|improve this answer

for resize form prophetically below code work better then other..


share|improve this answer

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;
share|improve this answer

in the form load event add this line

this.WindowState = FormWindowState.Maximized;
share|improve this answer

try this. this may help you to answer your problem. it work,i tried it http://www.codeproject.com/Tips/743923/Csharp-Automatic-resize-controls-runtime


share|improve this answer
Please don't post link-only answers; please put the relevant parts in your answer text itself. –  Scott Barta Mar 15 at 14:53

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).

share|improve this answer

Your Answer


