I'm making a small Windows Form application that contains a lot of grid views. I want all the grid views to resize with the window. I could make a function that detects window resize and then changes the size of each grid view but that feels a bit clunky. Is there an easier/more intelligent way to do this?
+2
A:
Set the Dock
property of the DataGrid view to DockStyle.Fill
Use the Dock property to define how a control is automatically resized as its parent control is resized. For example, setting Dock to DockStyle.Left causes the control to align itself with the left edges of its parent control and to resize as the parent control is resized. Controls are docked in their Z-order, which is the visual layering of controls on a form along the form's Z-axis (depth).
dataGridView1.Dock = DockStyle.Fill;
Fill All the control's edges are docked to the all edges of its containing control and sized appropriately.
SwDevMan81
2010-06-14 11:44:40
+2
A:
The properties Dock
, Anchor
, Padding
and Margin
are your friends here. They are designed to make almost all resizing-by-hand worthless.
Humberto
2010-06-14 11:48:09
Fill is not a property
DevDemon
2010-06-14 13:27:56
My guess is Humberto meant Dock instead of Fill. Dock is a valid property and Fill is a valid value for Dock
NascarEd
2010-06-14 14:00:38
@NascarEd exactly. Edited!
Humberto
2010-06-14 14:05:58
Thanks for the update. Could you add the links to each property?
DevDemon
2010-06-14 14:16:16
[Dock](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx), [Anchor](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor.aspx), [Padding](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.padding.aspx), and [Margin](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.margin.aspx).
Humberto
2010-06-14 14:24:24