Resizing Controls with Form Visual Studio C# VB.net

I can remember having to write the code to resize control in forms. These days Microsoft have made it much easier with the Anchor property.

When you put a control on a form, e.g. a listbox, you’ll find that by default resizing the form leaves the control the same distance from the top and left-hand side of the form:

Before Resize:

After Resize:

If you select the ListBox, then in the properties go and click on the Anchor property you will see this:

The greyed out boxes show that the control is pinned to the form at these places, i.e. the Left and the Top.

So, if we want the control to expand horizontally when we expand the form we can click on the right-hand box to pin the control to that side of the form as well:

With the right side of the control pinned resizing the form pulls the right hand edge of the control with it:

Removing the pinning on the left-hand edge of the control:

Will allow the control to be dragged with the form when resized:

You can experiment with different combinations of Anchors to see what effects they have.

Advertisements
This entry was posted in Programming and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s