How to resize form elements when resizing a window?

I have this form with a tab control and a list inside:

enter image description here

When I resize the window, I get something like this:

enter image description here

However, I really wanted the tab control and list to resize to get the following result:

enter image description here

I believe that I could achieve this effect by simply responding to some onResize() method on the form, and do my own calculations to manually update the size of the tab control and the corresponding list.

However, I have seen many applications achieve this effect, so I suspect there is a better way to do this - perhaps a built-in function.

Do you know the best way to achieve this effect?

+6
source share
7 answers

Here is a good tutorial that explains how to resize winform controls when resizing a container control using dock and binding properties:

http://www.techrepublic.com/article/manage-winform-controls-using-the-anchor-and-dock-properties/6165908

By setting four values ​​for the snap property (top, right, bottom, left), you can make the edges of the control remain stationary relative to the form control, even if it is modified.

+8
source

You can use the tab property of the tab control - just snap all four sides.

+5
source

You can use the Dock property from both tabs and the list to populate

+1
source

This can help:

 Private Sub frmMain_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged 'tab container sizechanged event tabMain.Dock = DockStyle.None 'set dock to none to allow resize tabMain.Size = New Size(New Point(3, 3)) ' set size anything you want tabMain.Dock = DockStyle.Fill 'set dock to fill to fit to container End Sub 
+1
source

You use the Dock and Anchor properties to control the resizing of an element's control when its parent / container is resized.

To make a control, fill its container, just

 theControl.Dock = System.Windows.Forms.DockStyle.Fill 

To save some fields, set the Anchor property

 theControl.Anchor = CType((System.Windows.Forms.AnchorStyles.Top _ Or System.Windows.Forms.AnchorStyles.Bottom _ Or System.Windows.Forms.AnchorStyles.Left _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) 

You can also set these properties in the Properties tool window.

0
source

To get the desired result, place the control as you want it to be in standard size form. then use the Anchor property for Top, Bottom, Left, Right. this allows you to specify that you always want the control to be relatively positioned in the form based on the smallest size.

that is: Set the anchor property: Top, Bottom, Left, Right, this ensures that the top, bottom, left, and right edges of the control will always be at the same distance from each edge, regardless of the size of the parents.

If you want the control to be located at a certain distance from each edge of the control surface, use Anchor Top, Bottom, Left, Right

if you want the top and left edges of the control to block 8 pixels from the top and left edges of the parent, set the Anchor property to the upper position. To the left, the control will never resize it, it will always remain relatively 8.8.

0
source

Press tab 1 or tab 2 Then from the side in the Property Tab find the Dock property. Then select the one in the middle or enter the full text.

or

You can find Anchor and select the bottom tab , top tag , right tag and left tag .

Hope this helps!

0
source

All Articles