Читать книгу C# 24-Hour Trainer - Stephens Rod - Страница 25
Section I
The Visual Studio IDE and Controls
Lesson 2
Creating Controls
Arranging Controls
ОглавлениеThe Form Designer provides several tools to help you arrange controls at design time. The following sections describe some of the most useful: snap lines, arrow keys, the Format menu, and the Layout toolbar.
Snap Lines
When you drag a control around on the form, the Form Designer displays snap lines that show how the control lines up with the form and with other controls. Figure 2.5 shows the Form Designer displaying light blue snap lines indicating that the control is standard distances away from the form's top and left edges.
You can drag the control away from this position and, if you do so, the snap lines disappear. When you drag the control close to one of the form's edges, the control jumps to the standard distance and the Form Designer displays the snap lines again.
The Form Designer also displays snap lines to show how controls align. In Figure 2.6, I dragged a second Button below the first. Different snap lines show that:
● The second Button is the standard distance from the form's left edge.
● The second Button's left and right edges line up with the first Button's edges.
● The second Button is a standard distance below the first Button.
Other snap lines show how the control contents line up. In Figure 2.7 snap lines show that the Label is the standard distance from the second Button and that the Label's text baseline lines up with the baseline of the second Button.
For a more realistic example, consider Figure 2.8. In this figure I was laying out a small data entry form, and I wanted all of the Labels and TextBoxes to line up nicely. In this figure, snap lines show that the Street TextBox is lined up on the left and right with the other TextBoxes, is a standard distance from the TextBoxes above and below, is a standard distance from the form's right edge, and has its baseline lined up with the Street Label.
Arrow Keys
In addition to dragging controls with the mouse, you can move controls by pressing the arrow keys. Select one or more controls and then use the left, right, up, and down arrow keys to move the control(s) one pixel at a time. This method is slower than using the mouse but gives you finer control.
When you move controls with the arrow keys, the Form Designer doesn't display snap lines so you may want to keep an eye on the control's Location property in the Properties window to see where it is.
The Format Menu and Layout Toolbar
The Format menu contains many commands that arrange one or more controls. Table 2.2 summarizes the Format menu's submenus.
The Layout toolbar contains the same commands as the Format menu but in a handy toolbar so they're easier to use. The buttons display little pictures that show how they align controls.
NOTE
How these tools arrange controls depends on how you select the controls. One of the selected controls, normally the first one you select, is the group's dominant control. The dominant control is marked with white boxes at its corners, whereas the other controls are marked with black boxes.
When you use an arranging tool, the dominant control determines how the others are arranged. For example, if you select the Format Align Lefts command, the other controls are moved so their left edges line up with the dominant control's left edge.
To change the dominant control in a selected group, click the one you want to be dominant (without holding down the Ctrl or Shift keys).