Using Forms

Forms are the foundation for creating the interface of an application. You can use forms to add windows and dialog boxes to your application. You can also use them as containers for items that are not a visible part of the application's interface. For example, you might have a form in your application that serves as a container for graphics that you plan to display in other forms.

Properties

Many of a form's properties affect its physical appearance. The Caption property determines the text that is shown in the form's title bar; the Icon property sets the icon that is displayed when a form is minimized. The MaxButton and MinButton properties determine whether the form can be maximized or minimized. By changing the BorderStyle property, you can control the resizing behavior of the form.

Height and Width properties determine the initial size of a form; Left and Top properties determine the form's location in relation to the upper left-hand corner of the screen. The StartupMode property can be set to start the form in a maximized, centered, or normal state.

The Name property sets the name by which you will refer to the form in code. By default, when a form is first added to a project, its name is set to frm1, frm2, and so forth. It's a good idea to set the Name property to something more meaningful.

Many form properties correspond with other control properties that you can examine in Using OCX Controls. The form, however, is unique in that it does not reside on a form, but appears on the user's window. That is why the form's Left, Top, Width, and Height properties all correspond to the edge of the screen and not to a Form window.

In addition to the properties shared with the controls, the form has - among others -the following properties:

BorderStyle This property determines how the Form window responds to the user's efforts to resize it. Some values you may need are 0-None, which offers a form without any edge or title bar, 1-Fixed Single, which offers a non-sizable window (the user can close the window but not resize, minimize, or maximize the window), and 2-Sizable (the default), which offers a regular sizable window with maximize and minimize buttons.
ControlBox This property's value of True or False determines whether the form's Control menu appears. A Control menu is the menu that appears when you click a window's icon in the upper-left corner of the window. The Control menu enables you to move, size, minimize, maximize, and close a window.
Icon This property specifies an icon filename for the Windows taskbar icon that appears when the user minimizes the form.
MaxButton This property determines whether the form contains an active Maximize window button.
MinButton This property determines whether the form contains an active Minimize window button. (If you set both the MaxButton and MinButton properties to False, neither appears on the form.)
Movable This property determines if the user can move the form or if the form is to remain in its displayed location.
Sizeable This property determines if the user can size the form.
ShowInTaskbar This property's True or False value determines whether the open form appears on the user's Windows taskbar.
StartUpMode This property provides a quick way to specify the starting position of the form on the screen. One of the most useful values is 2-Center that centers the form on the user's screen when the form first appears.

Load a form

To make a form visible and make your application run, you would use the following piece of code:

LoadForm frm1

Do

Sleep

Until Me Is Nothing

This loads the form settings from the internal data and brings it on the screen. The Do loop makes sure that it stays active. When the form is closed the Me variable will no longer reference a valid form and the loop will end. Me always holds the current active form.

- Now, press F5 to run the program.

Forms can perform methods and respond to events.

The Resize event of a form is triggered whenever a form is resized, either by user interaction or through code. This allows you to perform actions such as moving or resizing controls on a form when its dimensions have changed.

The Activate event occurs whenever a form becomes the active form; the Deactivate event occurs when another form or application becomes active. These events are convenient for initializing or finalizing the form's behavior. For example, in the Activate event you might write code to highlight the text in a particular text box; in the Deactivate event you might save changes to a file or database.

Next:Using OCX Controls

Using Event Procedures

{Created by Sjouke Hamstra; Last updated: 25/10/2014 by James Gaite}