Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic resizing of the Windows Forms controls

Tags:

c#

.net

winforms

I'm using VS2008's designer for doing this.

For example if I've a windows form of size say 500x500 and I added a DataGridView to it (490x490).

when I run this program. and maximize the form, the DataGridView still remains of the same size. rest of the additional space is blank on the form. I want DataGridView to also take the entire window size.

No software will be like that. I don't know what to change inorder get desired behaviour.

like image 570
claws Avatar asked Oct 28 '09 10:10

claws


People also ask

How do I resize a Windows Form?

By dragging either the right edge, bottom edge, or the corner, you can resize the form. The second way you can resize the form while the designer is open, is through the properties pane. Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it.

Is it possible to resize a control within the form design window?

To resize multiple controls on a form In Visual Studio, hold down the Ctrl or Shift key and select the controls you want to resize. The size of the first control you select is used for the other controls.

How do I stop windows from resizing a form?

First, select the form. Then, go to the properties menu. And change the property "FormBorderStyle" from sizable to Fixed3D or FixedSingle.

What Windows form controls?

Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client-side, Windows-based applications. Not only does Windows Forms provide many ready-to-use controls, it also provides the infrastructure for developing your own controls.


2 Answers

You can use Dock, or for more precise control use the Anchor property. By setting Anchor to Left, Right, Top, Bottom the control will scale with the window. By setting Anchor to Right the control will move with the right border. By setting Anchor to Top and Bottom the control will scale vertically, but have a fixed width. Just experiment

like image 88
sindre j Avatar answered Sep 28 '22 19:09

sindre j


You can ether set the Dock-Property of your DataGridView instance to DockStyle.Fill or use the Anchor-Property and set the anchors to:

dataGridView.Anchor =      AnchorStyles.Bottom |      AnchorStyles.Right |      AnchorStyles.Top |      AnchorStyles.Left; 

The first method will make your DataGridView to fill your whole client area. The second method will keep the ratio and only resize the control if the container resizes.

like image 20
Frank Bollack Avatar answered Sep 28 '22 19:09

Frank Bollack