Formatting Controls
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| Exam 70-526 Preparation Guide: Configure controls on a Windows Form at design time to optimize the UI. |
Contents |
Lining up controls in a graphical environment can be a difficult process. Having the grid on the form can help this process, but sometimes you need to line up several controls on a common line. Under the Format menu, there are many items that can help you to align and size controls on a particular placement or to a particular control.
The Format menu is in general used on groups of controls. When highlighting a group of controls, one of the controls will be the main control. The sizing handles of this control are coloured white, while the other controls have sizing handles coloured black. When applying any of the format options that are on this menu, the main control will be the one from which all of the other controls get sizing and formatting options applied to them.
Align
This sub-menu allows the alignment of selected controls with each other using the main control as the alignment reference.
| Alignment | Description |
|---|---|
| Lefts | Puts the left-most edges in line with the main control. |
| Centers | Puts the center of the controls in line with the main control. |
| Rights | Puts the right-most edges of the controls in line with the main control. |
| Top | Puts the top of the controls in line with the main control. |
| Middles | Puts the middle of the controls in line with the main control. |
| Bottoms | Puts the bottom of the controls in line with the main control. |
| To Grid | Snaps the top left of the selected control to the closest grid. |
Make same size
Using the main control as a reference, the Make Same Size menu option makes the other selected controls the same size as the main control.
| Sizing | Description |
|---|---|
| Width | Adjusts the width of all selected controls to the width of the main control. |
| Height | Adjusts the height of all selected controls to the height of the main control. |
| Both | Adjusts both the width and the height of all selected controls to the width and height of the main control. |
Horizontal spacing
The options under this menu change the horizontal spacing between selected controls.
| Spacing | Description |
|---|---|
| Make Equal | Makes equal space between the selected controls using the left and right controls as the end points. |
| Increase | Increases the horizontal spacing by one grid unit based on the control with focus. |
| Decrease | Decreases the horizontal spacing by one grid unit based on the control with focus. |
| Remove | Removes the horizontal space so that the controls are aligned with their edges touching, based on the control with focus. |
Vertical spacing
The options under this menu change the vertical spacing between selected controls.
| Spacing | Description |
|---|---|
| Make Equal | Makes equal space between the selected controls using the top and bottom controls as the end points. |
| Increase | Increases the vertical spacing by one grid unit based on the control with focus. |
| Decrease | Decreases the vertical spacing by one grid unit based on the control with focus. |
| Remove | Removes the vertical space so that the controls are aligned with their edges touching, based on the control with focus. |
Center in form
The items in this menu center the selected objects on the central axes of the form.
| Centering | Description |
|---|---|
| Horizontally | Aligns the middles of the selected controls to a horizontal line in the middle of the form. |
| Vertically | Aligns the centers of the selected controls to a vertical line in the center of the form. |
Order
The items in this menu change the order of the selected objects on a form.
| Order | Description |
|---|---|
| Bring To Front | Moves the selected controls to the front of all other objects on a Form. |
| Send To Back | Moves the selected controls behind all other objects on a Form. |
Lock controls
From the Format menu, you can choose the Lock Controls menu. When this is selected, all of the controls currently on the Form will be locked in place. Any attempts to move the controls will be unsuccessful until they are unlocked. Any controls added to the Form after the lock takes place will be unlocked.
|

