Adding Controls to the HelloUser Application
1. Stop the project if it is still running because you now want to add some controls to your form.
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 tool tip 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
3. If the Label control you have just drawn is not in the desired location, no problem. When the control
is on the form, you can resize it or move it around.To move it, click the control and drag it to the desired location.
The label automatically resizes 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 after you press Enter
or click 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. Directly beneath the label, you want to add a text box so that you can enter a name. You will
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 , 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.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 becomes underlined.
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. This snap line enables 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.
Source: Beginning Visual Basic 2015 by Bryan Newsome