Introduction to Building Forms With Visual Basic.NET
- Changing the Name of a Form
- Changing the Appearance of a Form
- Showing and Hiding Forms
- Summary
With few exceptions, forms are the cornerstones of every Windows application's interface. Forms are essentially windows and the two terms are often used interchangeably. More accurately, "window" refers to what's seen by the user and what the user interacts with, whereas "form" refers to what you see when you design. Forms let users view and enter information in a program. Such information may be text, pictures, graphsalmost anything that can be viewed on the screen. Understanding how to design forms correctly will allow you to begin creating solid interface foundations for your programs.
NOTE
Visual Basic.NET uses a new forms engine called Windows Forms, which is different from the engine used in previous versions of Visual Basic.
Think of a form as a canvas on which you build your program's interface. On this canvas, you can print text, draw shapes, and place controls with which users can interact. The wonderful thing about Visual Basic forms is that they behave like a dynamic canvas; not only can you adjust the appearance of a form by manipulating what's on it, you can also manipulate specific properties of the form itself.
Some basic properties of form appearance which you will want to manipulate include:
- Text
- Height
- Left
- Top
- Width
The capability to tailor your forms, however, goes far beyond these simple manipulations. More complex actions can include:
- Adding controls to a form
- Positioning, aligning, sizing, spacing, and anchoring controls
- Creating intelligent tab orders
- Creating transparent forms
- Creating forms that always float over other forms
- Creating Multiple Document Interfaces
In this article, I'll present some of the very basics of formsadding them to a project, manipulating their properties, and showing and hiding them using Visual Basic code. Once you have learned these nuts and bolts, you'll be ready for more advanced form techniques.
Changing the Name of a Form
The first thing you should do when you create a new object is give it a descriptive name. Start Visual Basic now (if it's not already running), and create a new Windows Application titled Forms Example. Using the Properties window, change the name of the form to fclsExample. When you need to create a new instance of this form, you'll use this name rather than the default generic name of Form1.