Forms Object


Forms Object

Location

My.Forms

Description

The My.Forms object provides design-time and runtime access to all defined forms in a Windows Forms project. As forms are added to the project, this object is automatically updated to include the new form. For instance, if your project contains a form named "Form1," it is accessed through:

     My.Forms.Form1 

This returns a reference to the System.Windows.Forms.Form object for Form1, from which all of the relevant members can be accessed.

As a shortcut, the "My.Forms" prefix can be left off of references to forms. This allows your code to reference forms as was done in pre-.NET Visual Basic. The statement:

     Form1.Show(  ) 

is equivalent to:

     My.Forms.Form1.Show(  ) 

For code located within Form1, all references to itself should use Me instead of Form1.

     Me.Show(  ) 

If you use My.Forms to access a form that has not yet been instantiated, it is instantiated immediately. Setting this instance to Nothing will release the instance.

     My.Forms.Form1 = Nothing 

To test whether a form has yet been instantiated, test the My.Forms reference for Nothing.

     If (My.Forms.Form1 Is Nothing) Then... 

Public Members

The My.Forms object has no members other than each specific form defined within the project.

Usage at a Glance

  • This object and its members are only valid in Windows Forms applications.

  • Use the My.Application.OpenForms property to retrieve a collection of all forms currently open within the application.

Example

This sample displays a specific form if it is not yet displayed.

     If (My.Forms.ToolboxForm Is Nothing) Then _        My.Forms.ToolboxForm.Show(  ) 

Related Framework Entries

  • System.Windows.Forms.Form Class

See Also

My Namespace, OpenForms Property, Resources Object, Settings Object, WebServices Object




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net