Export (0) Print
Expand All

Visual Basic Reference

Visual Studio 6.0

Form Object, Forms Collection

See Also    Example    Properties    Methods    Events

A Form object is a window or dialog box that makes up part of an application's user interface.

A Forms collection is a collection whose elements represent each loaded form in an application. The collection includes the application's MDI form, MDI child forms, and non-MDI forms. The Forms collection has a single property, Count, that specifies the number of elements in the collection.

Syntax

Form

Forms(index)

The placeholder index represents an integer with a range from 0 to Forms.Count - 1.

Remarks

You can use the Forms collection to iterate through all loaded forms in an application. It identifies an intrinsic global variable named Forms. You can pass Forms(index) to a function. whose argument is specified as a Forms class.

Forms have properties that determine aspects of their appearance, such as position, size, and color; and aspects of their behavior, such as whether or not they are resizable.

Forms can also respond to events initiated by a user or triggered by the system. For example, you could write code in a form's Click event procedure that would enable the user to change the color of a form by clicking it.

In addition to properties and events, you can use methods to manipulate forms using code. For example, you can use the Move method to change a form's location and size.

A special kind of form, the MDI form, can contain other forms called MDI child forms. An MDI form is created with the MDI Form command on the Insert menu; an MDI child form is created by choosing New Form from the File menu and then setting the MDIChild property to True.

You can create multiple instances of forms in code by using the New keyword in Dim, Set, and Static statements.

When designing forms, set the BorderStyle property to define a form's border, and set the Caption property to put text in the title bar. In code, you can use the Hide and Show methods to make forms invisible or visible at run time.

Note   Setting BorderStyle to 0 removes the border. If you want your form to have a border without the title bar, Control-menu box, Maximize button, and Minimize button, delete any text from the form's Caption property, and set the form's ControlBox, MaxButton, and MinButton properties to False.

Form is an Object data type. You can declare variables as type Form before setting them to an instance of a type of form that was declared at design time. Similarly, you can pass an argument to a procedure as type Form.

Forms also can act as sources in a DDEconversation, with a Label, PictureBox, or TextBox control furnishing the data.

You can access the collection of controls on a Form using the Controls collection. For example, to hide all the controls on an Form you can use code similar to the following:

For Each Control in Form1.Controls
   Control.Visible = False
Next Control
Show:
© 2014 Microsoft