LocationMy.Forms DescriptionThe 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 MembersThe My.Forms object has no members other than each specific form defined within the project. Usage at a Glance
ExampleThis 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
See AlsoMy Namespace, OpenForms Property, Resources Object, Settings Object, WebServices Object |