Project PRoVBVs2010

The Form Designer opens by default when a new project is created. If you have closed it, then you can easily reopen it by right-clicking Forml.vb in the Solution Explorer and selecting View Designer from the pop-up menu. From this window, you can also bring up the Code view for this form. However, Figure 1-13 illustrates the default view you see when your project template completes. On the screen is the design surface upon which you can drag controls from the Toolbox to build your user interface and update properties associated with your form.

The Properties pane, shown in more detail in Figure 1-14, is by default placed in the lower-right corner of the Visual Studio window. Like many of the other windows in the IDE, if you close it, it can be accessed through the View menu. Alternatively, you can use the F4 key to reopen this window. The Properties pane is used to set the properties of the currently selected control, or for the Form as a whole.

FIGURE 1-13

Each control you place on your form has its own distinct set of properties. For example, in the Design view, select your form. You'll see the Properties window adjust to display the properties of Form1 (refer to Figure 1-14). This is the list of properties associated with your form. If you want to limit how small a user can reduce the display area of your form, then you can now define this as a property.

For your sample, go to the Text property and change the default of Form1 to "Professional VB.NET." Once you have accepted the property change, the new value is displayed as the caption of your form. Later in this section, you'll set form properties in code. You'll see that .NET properties are defined within your source file, unlike other environments where properties you edit through the user interface are hidden in some binary or proprietary portion of the project.

Now that you've looked at the form's properties, open the code associated with this file by either right-clicking Form1.vb in the Solution Explorer and selecting Code view, or right-clicking the form in the Design view and selecting View Code from the pop-up menu.

The initial display of the form looks very simple. There is no code in the Form1.vb file. Visual Basic 2005 introduced a capability called partial classes. Partial classes are covered briefly in Chapter 2, and Visual Studio leverages them for the code, which is generated as part of the user interface designer.

fpropertie^^

" n

1 Form I SyKtpm.WiniJowR.Forms.Form * 1

nm<|j]

Font

Microsoft Sans Serif. 7.8pt

-

FuieCulor

| CurilrulTexL

FormBorderStyle

Sizable

RightToLeft

No

RightToLeftLayout

False

■ Text

Professional VB.NET

=

UseWaitCursor

False

M Behavior

AllowDrop

False

Auto Validate

Enable PreventFocusC hangt

ContexlMenuSlfip

(none)

DoublcBuffcrcd

False

Fnahleri

True

ImeMode

NoControl

1 * Data

1 ' (ApplicationSettinqs)

1 " (DataBindings)

Tay

1 A Design

-

1 Text

FIGURE 1-14

Visual Studio places all the generated source code for your form in the file Form1.Designer.vb. Because the "Designer" portion of this name is a convention that Visual Studio recognizes, it hides these files by default when you review your project in the Solution Explorer. As noted earlier, by asking Visual Studio to "show all files," you can find these generated files. If you open a "Designer.vb" file, you'll see that quite a bit of custom code is generated by Visual Studio and already in your project.

To do this, go to the toolbar located in the Solution Explorer window and select the Show All Files button. This will change your project display and a small plus sign will appear next to the Form1.vb file. Expanding this entry displays the Form1.Designer.vb file, which you can open within the IDE. Doing this for Form1.Designer.vb for the ProVB_VS2010 project you created will result in a window similar to the one shown in Figure 1-15.

FiGURE 1-15

Note that the contents of this file are generated. For now, don't try to make any changes. Visual Studio automatically regenerates the entire file when a property is changed, so any changes you make will be lost. The following lines start the declaration for your form in the file Form1.Designer.vb:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1

Inherits System.Windows.Forms.Form

Code snippet from Forml.Designer

The first line is an attribute that can be ignored. Next is the line that actually declares a new class called Form1. Note that in spite of the naming convention used by Visual Studio to hide the generated UI class implementation, the name of your class and the file in which it exists are not tightly coupled. Thus, your form will be referenced in the code as Form1 unless you modify the name used in the class declaration. Similarly, you can rename the file that contains the class without changing the actual name of the class.

One powerful result of forms being implemented as classes is that you can now derive one form from another form. This technique is called visual inheritance, although the elements that are actually inherited may not be displayed.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment