Checking the Visual Basic .NET Installation

Now that the Visual Studio .NET Professional installation is complete, you should check to see that everything in the installation works properly. A good way to do that is to write a simple Visual Basic .NET program.

Starting Visual Studio .NET

Before you can write your first Visual Basic .NET program, you need to get Visual Basic .NET up and running. The easiest way to do that is to click the Windows Start button. Then select Programs, Microsoft Visual Studio .NET, and Microsoft Visual Basic .NET. The Visual Basic .NET development environment launches.

When you see the opening screen, select File, New, Blank Solution (see Figure 1.26). If you've done this correctly, your screen should look similar to that shown in Figure 1.26.

Figure 1.26. Creating a new solution from the Visual Basic .NET startup screen.


Chapter 2, "The Basics of Object-Oriented Programming," discusses solutions, projects, and files, and other programming details. For now, you can just follow the directions in this chapter and know that you'll learn the details later.

Using Figure 1.27 as a guide, select Windows Application from the Templates box and type HelloWorld in the Name box. The Location box asks you where you want to store the program you are about to write. This is entirely up to you. However, I urge you to have some method to your madness. In the example in this chapter, I have selected the directory named C:\VBN\Ch1 . As you might guess, this means that I have a VBN directory on disk drive C: with a subfolder for each chapter in this book. Using this type of method makes it easy to find the programs you write as you progress through the chapters in the book. You should enter whatever directory you want to use in the Location box. If the directory does not already exist, you can check the Create Directory for Solution box, as shown in Figure 1.27. You can click More to view the project path . When you're done making all the needed changes to this screen, click OK to continue.

Figure 1.27. The New Project screen.


You are now prompted to save the changes you have made thus far (see Figure 1.28). Click Yes to save the changes you have made.

Figure 1.28. Saving the changes for a project.


The Visual Basic .NET Integrated Development Environment

At this point, your display screen should look similar to Figure 1.29. This is the Visual Basic .NET Integrated Development Environment (IDE). Virtually all your program-writing activity takes place in the IDE. The IDE is a single program in which you write programs, run and test programs, correct program errors, and make subsequent program modifications. Virtually all phases of program development are done within the IDE.

Figure 1.29. The Visual Basic .NET IDE.


The Toolbox

Approximately the left third of the Visual Basic .NET IDE is a toolbox that holds the basic objects you will use to create programs. The objects in the toolbox are often called components , or controls, and each of them is designed to perform some specific programming task.

Programmer's Tip


Programmers who have experience using earlier versions of Visual Basic often prefer the term controls over components to describe the objects presented in the toolbox. This preference goes back to the days when Visual Basic first introduced ActiveX controls. It's not important whether you call them components or controls: Simply keep in mind that they are actually objects that you can use in programs. This book refers to them as controls.

The Forms Window

The middle third of the Visual Basic .NET IDE is the Forms window, with a form shown in that window. You can think of a form as an object on which you place components from the toolbox. By arranging the desired toolbox objects on a form, you can create the visual appearance of what you want a program to look like. You can also click on the tab near the top of the middle window to examine any code that might be associated with the form or any of its components.

The Properties Window

On the right third of the Visual Basic .NET IDE is the Properties window. In the Properties window in Figure 1.29, you can see a label control outlined with a shaded box and the words Hello World in it. The eight small white squares on the outline of the label show that Visual Basic .NET is currently working with that label component. There could be dozens of other components on the form, but the one with the little white squares has Visual Basic .NET's attention at the moment. Because Visual Basic .NET is concentrating on the label control in the Forms window, the Properties window shows all the properties associated with that label control.

The properties of a component describe the current state of the component. What is meant by the term current state of a component? Suppose, for example, that someone asked you to describe yourself. What would you tell that person? You might describe your height, your weight, the color of your eyes and hair, what you are wearing , your age, and so on. Each of those things is a property, or an attribute, and collectively those properties describe your current state. Next month, you might have lost weight, dyed your hair, put in colored contact lenses, had a face lift, and changed your clothes; this would lead to an entirely different description of yourself ”an entirely different state. In other words, you can change your state by changing the values of the properties, or attributes, that describe you.

In similar fashion, you can also change the properties of a Label control. For example, if you look closely at Figure 1.29, you see a property labeled Text that is currently set to "Hello World" . (You can also see this in the Forms window.) If you change the Text property of the label, you also change the state of the label object. You can scroll through the list of properties to see all the attributes that collectively define the current state of the label object.

If there were another object on the form in the center of Figure 1.29, you could click it, and the small white squares would outline the object. This would mean that Visual Basic .NET would then be focused on the object you just clicked. You would also notice that the Properties window would change to display the properties associated with the object you just clicked on in the Forms window. Therefore, clicking an object in the Forms window causes the Properties window to be updated with the properties for that object.

Moving an Object from the Toolbox to a Form

To select a component from the toolbox, you click on the Windows Forms bar just below the toolbox bar. (You can see this in Figure 1.29.) A menu of components that you can add to a form then appears. Suppose you want to select a label component and place it on the form. There are two ways to add a component to a form. One way is to click the A Label component and then move the cursor over to the form and click the form to deposit the label on the form. A second way is to double-click the A Label object, which automatically places a label near the middle of the form. It really doesn't matter which method you use. When the label object is on the form, you can drag it to the place where you want it to reside on the form. Notice the little white squares that outline the form and tell you that Visual Basic .NET is watching everything you are doing with the label.

Changing a Property Value

As mentioned previously, Visual Basic .NET is watching what you are doing with the label object, and the Properties window presents a list of all the properties associated with a label object. As an example of changing a property value, move to the Text property in the Properties window, place the cursor in the text box to the right of the Text field, type Hello World , and press the Enter key.

Right below the Text property in the Properties window is the TextAlign property. (By default, the properties are listed in alphabetical order in the Properties window.) If you click on TextAlign property's text box, you are presented with a drop-down arrow that, when clicked, presents a graphical representation of where you can align the text within the label object. In Figure 1.29, the TextAlign property is set to its default value of top-left . By clicking the graphical box representation, you can position the text almost anywhere you want within the label control. After you've selected a position via the graphical selection process, Visual Basic .NET translates your selection into English and writes it in the TextAlign property's text box. You can try playing around with the TextAlign property to see this in action. Make sure you understand how the TextAlign property works and the effect the different choices have on the placement of the text within the label.

Just for grins, try selecting the Font property, and then click the Bold option; notice the effect this has on the text in the label on the form. Now move up to the BorderStyle property and select the Fixed3D option and observe its effect. Personally, I almost always have the Font property for labels and text boxes set to Bold and the BorderStyle property for labels set to Fixed3D . These are my personal preferences, and you are free to use whatever looks best to you.

Visual Basic .NET. Primer Plus
Visual Basic .NET Primer Plus
ISBN: 0672324857
EAN: 2147483647
Year: 2003
Pages: 238
Authors: Jack Purdum

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: