Visual Basic and Forms

From Techotopia
Revision as of 18:04, 18 July 2007 by Neil (Talk | contribs)

Jump to: navigation, search

The Windows Form is a vital component in the development of any Windows-based application. Forms essentially provide the windows that make up a Windows application. In fact, the terms window and form are often used interchangeably. Forms allow the Visual Basic developer to create windows and layout controls (such as buttons, labels etc) in those forms to provide the application's user interface.

In the next chapter (Designing Forms in Visual Basic) we will look at how to layout controls inside a form. Before we reach that stage, however, there are a surprising number of ways in which the form itself can be modified and configured. We will cover these options in detail in this chapter.

Creating a New Form

Throughout this chapter we will work with a form in a new project. Begin by starting Visual Studio and creating a new Windows Application project (see Creating a New Visual Basic Project for details of how to do this). Name the project VBforms.

Once the new project is created you will see a Form in Visual Studio ready for you to begin work.

Changing the Form Name

All objects in a Visual Basic application need a name so that they can be referenced in the code. When a new object is added to an application in Visual Studio it is assigned a default name which usually consists of the object type and a number. For example the first form object in an application is named Form1, the second Form2, and so on.

To change the name of a Form to something more meaningful simply click in any area of the Form in Visual Studio and change the (Name) value in the Properties panel.

Changing the Form Title

Each form represents an application window. The text displayed in the title bar for each window should be changed to display something meaningful. This should eiher be the name of application, or a description of the form's function (for example Order Entry or Sales Report).

The value of the text to be displayed in the window title is defined by the form's Text property. To change the title of the form, therefore, select the Text value in the Property panel and change it to a new value (for example, 'My Form Example').