Export (0) Print
Expand All

MainMenu.GetForm Method

Gets the Form that contains this control.

[Visual Basic]
Public Function GetForm() As Form
[C#]
public Form GetForm();
[C++]
public: Form* GetForm();
[JScript]
public function GetForm() : Form;

Return Value

A Form that is the container for this control. Returns a null reference (Nothing in Visual Basic) if the MainMenu is not currently hosted on a form.

Remarks

This property enables you to determine if a specific MainMenu is parented to a form. The property is typically used when multiple MainMenu objects are being used on a form and you need to determine which one is currently being used by a form.

Example

[Visual Basic, C#, C++] The following example uses the GetForm method to determine if a MainMenu is currently parented to the form. If the call in the example code to GetForm does not return a null, the code then clones the menu structure of the MainMenu using the CloneMenu method. The code then sets the RightToLeft property to true on the new copy of the MainMenu to create a MainMenu that can be used for languages that support right to left text. This example assumes that you have a MainMenu created that is named mainMenu1.

[Visual Basic] 
Public Sub CloneMyMenu()
    ' Determine if mainMenu1 is currently hosted on the form.
    If Not (mainMenu1.GetForm() Is Nothing) Then
        ' Create a copy of the MainMenu that is hosted on the form.
        Dim mainMenu2 As MainMenu = mainMenu1.CloneMenu()
        ' Set the RightToLeft property for mainMenu2.
        mainMenu2.RightToLeft = RightToLeft.Yes
    End If
End Sub


[C#] 
public void CloneMyMenu()
{
   // Determine if mainMenu1 is currently hosted on the form.
   if(mainMenu1.GetForm() != null)
   {
      // Create a copy of the MainMenu that is hosted on the form.
      MainMenu mainMenu2 = mainMenu1.CloneMenu();
      // Set the RightToLeft property for mainMenu2.
      mainMenu2.RightToLeft = RightToLeft.Yes;
   }
}


[C++] 
public:
 void CloneMyMenu()
 {
    // Determine if mainMenu1 is currently hosted on the form.
    if(mainMenu1->GetForm() != 0)
    {
       // Create a copy of the MainMenu that is hosted on the form.
       MainMenu* mainMenu2 = mainMenu1->CloneMenu();
       // Set the RightToLeft property for mainMenu2.
       mainMenu2->RightToLeft = RightToLeft::Yes;
    }
 }
 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MainMenu Class | MainMenu Members | System.Windows.Forms Namespace | Form

Show:
© 2015 Microsoft