In Visual Basic, the form is the container for all the controls that make up the user interface. When a Visual Basic application is executing, each window it displays on the desktop is a form. The terms form and window describe the same entity. A window is what the user sees on the desktop when the application is running. A form is the same entity at design time. The proper term is a Windows form, as opposed to a web form, but I will refer to them as forms. This term includes both the regular forms and dialog boxes, which are simple forms you use for very specific actions, such as to prompt the user for a particular piece of data or to display critical information. A dialog box is a form with a small number of controls, no menus, and usually an OK and a Cancel button to close it.
Forms have a built-in functionality that is always available without any programming effort on your part. You can move a form around, resize it, and even cover it with other forms. You do so with the mouse or with the keyboard through the Control menu.
In previous chapters, you concentrated on placing the elements of the user interface on forms, setting their properties, and adding code behind selected events. Now, you’ll look at forms themselves and at a few related topics.
The Appearance of Forms
Applications are made up of one or more forms — usually more than one. You should craft your forms carefully, make them functional, and keep them simple and intuitive. You already know how to place controls on the form, but there’s more to designing forms than populating them with controls. The main characteristic of a form is the title bar on which the form’s caption is displayed (see Figure 5.1).
Clicking the icon on the left end of the title bar opens the Control menu, which contains the commands shown in Table 5.1. On the right end of the title bar are three buttons: Minimize, Maximize, and Close. Clicking these buttons performs the associated function. When a form is maximized, the Maximize button is replaced by the Restore button. When clicked, the Restore button resets the form to the size and position before it was maximized, and it’s replaced by the Maximize button. To access the Control menu without a mouse, press Alt and then the down arrow key.
Figure 5.1 – The elements of the form
Table 5.1 – Commands of the Control Menu of the Form
|Restore||Restores a maximized form to the size it was before it was maximized; available only if the form has been maximized.|
|Move||Lets the user move the form around with the arrow keys.|
|Size||Lets the user resize the form with the arrow keys.|
|Minimize||Minimizes the form.|
|Maximize||Maximizes the form.|
|Close||Closes the current form. (Closing the application's main form terminates the application.)|