After you have added controls, it is important to align them consistently to create an attractive user interface. For forms that require a considerable amount of data entry, it is also important that the order of the controls is properly defined so that the user can tab through them easily. In addition, forms that can be resized at run time should be able to resize controls appropriately. The key to designing a successful user interface is the proper handling of layout, alignment, and display of controls. The Forms Designer provides all the necessary tools to meet these requirements.
When you open a form in the Forms Designer, by default it is displayed with a dotted grid. This grid provides a graphical way to align controls. When you move controls on the form, they align on this grid automatically. Use the Options dialog box to change the size of this grid both horizontally and vertically.
Note You can also use the Options dialog box to specify whether to display a grid and whether to align controls on the grid.
To change the spacing of the form surface grid
If you want finer control over the location of controls on a form, enter a smaller pixel size for both the vertical and horizontal spacing options.
Although you can move controls around on a form and have them align on the Forms Designer grid, you can also align multiple controls on a form based on the location of another control. To make alignment of controls easier, the Forms Designer provides a set of alignment tools.
To align controls on a form
This is the control that the other controls will be aligned with.
Continue this process for all the controls that you want to align.
For example, clicking Lefts aligns all the selected controls at the left edge of the first control.
Using the alignment options, you can align by the left, right, top, bottom, center (vertical center of the first control), and middle (horizontal center of the first control) of the first control that is selected.
Another important aspect of designing a form is attractive spacing between controls. For example, setting the proper space between a Label control and its corresponding Edit control is necessary for the consistency of a form's design. The Forms Designer provides tools for setting the spacing between controls.
To set vertical spacing between controls
This is the control that will be used to set the vertical spacing for other selected controls.
Continue this process for all the controls that you want to set spacing for.
For example, clicking Increase increases the vertical spacing between the controls by one pixel. However, if you select Snap to grid in the Options dialog box, spacing increases by one grid point.
Using the spacing options, you can increase, decrease, remove, or make equal (if you have more than two controls selected) the vertical spacing between all the selected controls.
To set horizontal spacing between controls
This is the control that will be used to set the horizontal spacing for other selected controls.
Continue this process for all the controls that you want to set spacing for.
For example, clicking Decrease decreases the horizontal spacing between the controls by one pixel. However, if you select Snap to grid in the Options dialog box, spacing decreases by one grid point.
Using the spacing options, you can increase, decrease, remove, or make equal (if you have more than two controls selected) the horizontal spacing between all the selected controls.
After you have added controls to your form, you can make them the same size. Use the Make Same Size command to size the selected controls according to the size of the first control.
To make multiple controls the same size
This is the control that will be used to set the size for other selected controls.
Continue this process for all the controls that you want to make the same size as the first control.
For example, clicking Both sets the height and width of the selected controls with that of the first control you selected.
Depending on the type of user interface you are creating with your form, you can position a control in the center of the form either vertically or horizontally.
To center controls on the form
After you have added controls to your form and set their layout, you can to lock the controls in place so that they cannot be moved.
To lock the position of controls on a form
The controls are locked and cannot be moved unless you change their location properties using the Properties window. To unlock the controls, click Lock Controls again.
An important aspect of any user interface design is user interaction. In addition to providing the proper controls in an attractive layout, it is critical to make your user interface easy to navigate with both the mouse and the keyboard. Users can press the TAB key to navigate through the various controls on your form. Therefore, it is important that the tab order of your controls is indicative of how the form is to be used.
Note Controls that are placed in container controls, such as the GroupBox and Panel controls, have their own tab order within the container.
To set the tab order of a form
The Forms Designer displays numbered boxes next to each control on your form. These boxes indicate the current tab index of the control in the tab order.
Continue clicking controls in the order that you want them in the tab order.
This toggles the tab order view in the Forms Designer.
To test the tab order on your form, select the first control in the tab order and press TAB. The selection moves to the next control in the tab order. You can continue pressing TAB through the rest of the controls.
If you are designing a form that the user can resize at run time, the controls on your form should resize and reposition properly. To resize controls dynamically with the form, you can use the anchor property for all graphical WFC controls. The anchor property defines an anchor position for the control. When a control is anchored to a form and the form is resized, the control maintains the distance between the control and the anchor positions. For example, if you have an Edit control that is anchored to the left, right, and bottom edges of the form, as the form is resized, the Edit control resizes horizontally so that it matches the same distance from the right and side of the form. Also, the control positions itself vertically so that its location is always the same distance from the bottom edge of the form.
To anchor a control on a form
An editor is displayed that shows a cross.
Another way to lay out controls on your form is to dock them at the edges of your form or have them fill the control's container (either a form or a container control). For example, Windows Explorer docks its TreeView control to the left side of the window and its ListView control to the right side of the window. Use the dock property for all graphical WFC controls to define the docking mode.
To dock a control
An editor is displayed that shows a series of boxes representing the edges and the center of the form.
The control is automatically resized to fit the boundaries of the docked edge.