MainMenu.CloneMenu 方法

定義

建立新的 MainMenu,它是目前 MainMenu 的複本。

public:
 virtual System::Windows::Forms::MainMenu ^ CloneMenu();
public virtual System.Windows.Forms.MainMenu CloneMenu ();
override this.CloneMenu : unit -> System.Windows.Forms.MainMenu
Public Overridable Function CloneMenu () As MainMenu

傳回

MainMenu

MainMenu,表示複製的功能表。

範例

下列程式碼範例會 GetForm 使用 方法來判斷 目前是否 MainMenu 為表單上層。 如果範例程式碼中的 呼叫未傳回 null ,則程式碼 GetForm 接著會使用 CloneMenu 方法複製 的 MainMenu 功能表結構。 然後,程式碼會在 的新複本上將 RightToLeft 屬性設定為 true,以建立 MainMenu 可用於支援由右至左文字 MainMenu 的語言。 此範例會要求您已 MainMenu 建立名為 mainMenu1 的 。

void CloneMyMenu()
{
   // Determine if mainMenu1 is currently hosted on the form.
   if ( mainMenu1->GetForm() != nullptr )
   {
      // 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;
   }
}
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;
   }
}
Public Sub CloneMyMenu()
    ' Determine if mainMenu1 is currently hosted on the form.
    If (mainMenu1.GetForm() IsNot 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

備註

您可以使用這個方法來建立儲存在 中的 MainMenu 功能表結構複本。 您可以使用這個方法來重複使用儲存在 中的 MainMenu 功能表結構,做為新 MainMenu 的基礎。 例如,如果您想要建立功能表結構,其具有與現有 MainMenu 相同的功能表項目,但也會新增其他 MenuItem 物件,您可以使用 CloneMenu 方法來建立原始 MainMenu 的複本,然後將新 MenuItem 物件新增至複製 MainMenu 的 。

適用於