|
Creating,
|
| Running, and |
|
Terminating a Program |
|
Visual Basic
programming involves a combination of writing a portion of the program code yourself and
having Visual Basic generate the remaining code automatically. Here are the steps you perform to create, run and
terminate the first program:
1. Create the new project. To create a new Windows application select File > New > Project... to display the New Project dialog below. Click the Visual Basic Projects folder to display a list of project types. Select Windows Application. Name the project ASimpleProgram and select a directory in which you want to save it. To select a directory click the Browse... button, which opens the Project Location dialog. Navigate through the directories to locate the one that you wish to use and then click OK. The selected folder will appear in the Location text box. Click OK to close the New Project dialog. The IDE then loads the new single-project solution, which contains a form names Form1. 2. Set the text in the form's title bar. The text in the form's title bar is specified in the form's Text property. If the Properties window is not open, click the properties icon in the toolbar or select View > Properties Window. Clcik the form to display the form's properties in the Properties window. Click the textbox to the right of the Text properties box and type A Simple Program. Press the Enter key when finished, and the forms title bar is updated immediately. 3.
Resize the form. Click and drag one of the forms enabled sizing
handles, the small squares around a form shown below.
Gray sizing handles are disabled and a programmer cannot use them to resize forms. Sizing handles that are black are enabled them can
be used for resizing. These handles will not
be visible during program execution. 4. Change the forms background color. The BackColor property specifies a form or controls background color. Clicking BackColor in the Properties window causes a down arrow to appear next to the property value as shown below. When
clicked, the down arrow displays a window with the tabs System, Web and
Custom. Click the Custom tab to display the
palette, a group of colors from which the user selects. Select the box representing light blue. The palette disappears and the forms
background color changes to light blue. 5. Add a Label control to the form. Open the toolbox by clicking the Toolbox icon. Click the Windows Forms button in the Toolbox. Double-click the toolbox's Label control. This causes a label to appear in the upper-left corner of the form. You can also drag control from the Toolbox to the form. The Label displays the text Label1 by default. When a control is added to a form its BackColor property is set to the form's BackColor. 6.
Set the label's display. Select the label by clicking it. Its
properties appear in the Properties window. The label's
Text property
determines what text, if any, the Label displays.
The form and
label
each have their own Text property -- with each
being completely independent of the other. Forms
and controls can have properties with the same name without conflict. Set the label's Text property to Welcome
to Visual Basic! Note that when the edge of the label is reached, the
text automatically wraps to the next line. 7. Set the label's font size and align the label's text. Clicking the Font property value causes an ellipsis button to appear.
When this button is pressed the window below appears. The font name, font style, and font size can be selected. The current font is applied to the text in the Sample area. Under the Size category select 24 and press OK. Next, select the TextAlign property, which determines how the text is aligned within the label. A three-by-three gird of buttons representing alignment choices is displayed. The position of each button corresponds to where the text appears in the label. Click the top-center button in the three-by-three grid to position the text in the top-center position in the label. 8.
Name the
label. The
label's Name property is used to
identify the Label. The default name
for the label just created is Label1. Set the Name property to lblChoice. Be sure to prefix the Name of each label with lbl to make the label object easy to identify. 9. Add a button to the form. The button control can display a text label or an image. Locate the button in the Toolbox and then double click it to add it to the form. Move it below the label.
Most button names begin with cmd to signify a command. Rename your new button cmdFirefox. 10. Provide an image for the button. Click the button to display its properties. Locate the Image property, which displays (None). Click the ellipsis button to display the Open dialog. Browse for an image to insert, select it with the mouse and press Enter. The image will be displayed on the button. Make the button larger by resizing it. You may wish to delete the test. 11. Add another button, position it next to the first, name it cmdIE, and add the IE image.
12.Provide Code for each command. Click on each if the buttons in turn, adding code for each one as shown below. 13. Save the Project. Click the File > Save All to save the entire solution. The solution file contains the names and locations of its projects, and the project file contains the names and locations of all the files in the project.
14. Run the program. To run the program, click the Start button or select Start from the Debug menu.
15. Terminate the program. To end a program, click the running application's close button (the ´ in the top right corner). This returns the IDE to the design mode. 16. Print the program. To print the program click on the View Code button in the Solution Explorer window or double click the Form1.vb* tab in the designer window. Then click File > Print and select your default printer. Downloadable images from demo:
|