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 | | | | | | | | |______|
The Anchor Property determines how a control is automatically resized when its parent control is resized.
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.
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.
First, select the form. Then, go to the properties menu. And change the property "FormBorderStyle" from sizable to Fixed3D or FixedSingle.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With