The simplest way to stop your project is to click the close (X) button in the top-right corner of
the form. Alternatively, you can click the blue square on the toolbar (which displays a ToolTip
that says “Stop Debugging” if you hover over it with your mouse pointer).
2. Add a Label control to the form. Click Label in the Toolbox, drag it over to the form’s
Designer and drop it in the desired location. (You can also place controls on your form by
double-clicking the required control in the Toolbox or clicking the control in the Toolbox and
then drawing it on the form.)
3. If the Label control you have just drawn is not in the desired location, it really isn’t a problem.
When the control is on the form, you can resize it or move it around. Figure 12 shows what
the control looks like after you place it on the form. To move it, click the dotted border and
drag it to the desired location. The label will automatically resize itself to fit the text that you
enter in the Text property.
4. After drawing a control on the form, you should at least configure its name and the text that
it will display. You will see that the Properties window to the right of the Designer has
changed to Label1, telling you that you are currently examining the properties for the label.
In the Properties window, set your new label’s Text property to Enter Your Name. Note that,
once you press Enter or click on another property, the label on the form has automatically
resized itself to fit the text in the Text property. Now set the Name property to lblName.
5. Now, directly beneath the label, you want to add a text box, so that you can enter a name. You
are going to repeat the procedure you followed for adding the label, but this time make sure
you select the TextBox control from the toolbar. After you have dragged and dropped
(or double-clicked) the control into the appropriate position as shown in Figure 13, use
the Properties window to set its Name property to txtName.
Notice the sizing handles on the left and right side of the control. You can use these handles to
resize the text box horizontally.
6. In the bottom left corner of the form, add a Button control in exactly the same manner as you
added the label and text box. Set its Name property to btnOK and its Text property to &OK.
Your form should now look similar to the one shown in Figure 1-14.
The ampersand (&) is used in the Text property of buttons to create a keyboard shortcut (known as a hot key). The letter with the & sign placed in front of it will become underlined (as shown in Figure 14) to signal users that they can select that button by pressing the Alt+letter key combination, instead of using the mouse (on some configurations the underline doesn’t appear until the user presses Alt). In this particular instance, pressing Alt+O would be the same as clicking the OK button. There is no need to write code to accomplish this.
7. Now add a second Button control to the bottom right corner of the form by dragging the Button control from the Toolbox onto your form. Notice that, as you get close to the bottom right
of the form, a blue snap line appears, as shown in Figure 15. This snap line allows you to
align this new Button control with the existing Button control on the form. The snap lines
assist you in aligning controls to the left, right, top, or bottom of each other, depending on
where you are trying to position the new control. The light blue line provides you with a consistent margin between the edge of your control and the edge of the form. Set the Name property to btnExit and the Text property to E&xit. Your form should look similar to Figure 16.
No comments:
Post a Comment