Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Make a Form Fill the Window at Run Time
 

Make a Form Fill the Window at Run Time

I have noticed that whenever I run my programme, the form and its controls remain the size as was set at design time even when I click the Maximize button leaving empty spaces all over.

How do I get the form and its controls to fill the entire window proportionately and neatly; at positions similar to those I see at design time?

Thanks in advance.


Only performance counts!
Sylva  Wednesday, March 18, 2009 8:56 PM

Hi Sylva,

If you use controls like Panel, TabControl, RichTextBox etc and you want to keep these control show in the whole form, you can set the Dock property to Fill.

The Dock property is also important, it is mostly used by container kind of controls. You can dock your panel to the top/bottom/left/right or fill of the form.

Most Winform controls' Dock property is None and Anchor property is "Top, Left". You can change it to meet your need.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer bySylva Monday, March 23, 2009 8:35 PM
  •  
Kira Qian  Monday, March 23, 2009 3:33 AM
Every control has a property called "Anchor". It has 4 lines representing 4 different directions i.e. top, bottom, right and left. You need to play around with this and this is the easies way that you can fill your entire form or window according to the screen resolution.

Regards

Midnight Programmer
Prashant Khandelwal  Thursday, March 19, 2009 8:57 AM

Hi Sylva,

If you use controls like Panel, TabControl, RichTextBox etc and you want to keep these control show in the whole form, you can set the Dock property to Fill.

The Dock property is also important, it is mostly used by container kind of controls. You can dock your panel to the top/bottom/left/right or fill of the form.

Most Winform controls' Dock property is None and Anchor property is "Top, Left". You can change it to meet your need.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer bySylva Monday, March 23, 2009 8:35 PM
  •  
Kira Qian  Monday, March 23, 2009 3:33 AM
Prashant and Kira's comments are exactly what you need, if you need to cover the empty spaces on your form (after you maximize, or minimize).
However, if you need to make it start-up as maximized already, set the property WindowState on the designer to Maximized.

Or you can do it in run time, by doing this:

WindowState = FormWindowState.Maximized;

Hope this helps.


Rafael Medeiros
RMedeiros  Monday, March 23, 2009 6:12 PM

You can use google to search for other answers

Custom Search

More Threads

• how to add one more control in open dialog box
• Calling RaiseComponentChanging causes an error in VS2005
• Object does not match target type.
• Custom Control Painting
• LinkLabel
• Smart tags not show for custom control designer
• ContextMenuStrip behavior on a TreeView
• Monitor the Change of ActiveControl
• UserControl, Inherited Control, Abstract class, (C#)
• Displaying different image size in a listview.