Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically resize list boxes when resizing a form

Tags:

c#

winforms

I have a Windows Form with two list boxes on it. Also there is a label on top of each of them

listbox1
|      |
|      |
|______|

listbox2
|      |
|      |
|______|

When the user resizes the form (for example maximizes it), I would like the list boxes to automatically expand in height:

listbox1
|      |
|      |
|      |
|      |
|______|

listbox2
|      |
|      |
|      |
|      |
|______|
like image 421
gruber Avatar asked Nov 22 '10 15:11

gruber


People also ask

Which property of a control is used to make it automatically resize based on a resizing of its parent?

The Anchor Property determines how a control is automatically resized when its parent control is resized.

What is the use of AutoSize property in visual basic?

Use AutoSize to force a form to resize to fit its contents. A form does not automatically resize in the Visual Studio forms designer, regardless of the values of the AutoSize and AutoSizeMode properties. The form correctly resizes itself at run time according to the values of these two properties.

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

Resize with the designerBy 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.

How do I stop a form from being resized?

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


1 Answers

The listbox's 'Anchor' property is set to Top, Left by default. Select Bottom and Right as well and it will now resize.

However, I see that you have two listboxes (stacked on top of eachother), so the above suggestion will not get them both to resize evenly in a vertical manner. But it will solve the resizing horizontally for you.

In order to get both to resize vertically, you may need to use a grid splitter, and manually determine the correct position.

like image 133
Scott Avatar answered Nov 14 '22 22:11

Scott