This documentation is archived and is not being maintained.

MainMenu.CloneMenu Method

Creates a copy of the menu object.

Overload List

Creates a new MainMenu that is a duplicate of the current MainMenu.

[Visual Basic] Overloads Public Overridable Function CloneMenu() As MainMenu
[C#] public virtual MainMenu CloneMenu();
[C++] public: virtual MainMenu* CloneMenu();
[JScript] public function CloneMenu() : MainMenu;

Inherited from Menu.

[Visual Basic] Overloads Protected Sub CloneMenu(Menu)
[C#] protected void CloneMenu(Menu);
[C++] protected: void CloneMenu(Menu*);
[JScript] protected function CloneMenu(Menu);

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, C#, C++] Note   This example shows how to use one of the overloaded versions of CloneMenu. For other examples that might be available, see the individual overload topics.
[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.

See Also

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

Show: