tags:

views:

69

answers:

3

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?

+1  A: 

Take a look at the Anchor property of Control it might help.

Itay
+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
+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
Fill is not a property
DevDemon
My guess is Humberto meant Dock instead of Fill. Dock is a valid property and Fill is a valid value for Dock
NascarEd
@NascarEd exactly. Edited!
Humberto
Thanks for the update. Could you add the links to each property?
DevDemon
[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