MainMenu.GetForm 方法

定義

取得含有這個控制項的 Form

public:
 System::Windows::Forms::Form ^ GetForm();
public System.Windows.Forms.Form GetForm ();
member this.GetForm : unit -> System.Windows.Forms.Form
Public Function GetForm () As Form

傳回

Form

是這個控制項容器的 Form。 如果 MainMenu 目前不是裝載 (Host) 在表單上,則傳回 null

範例

下列程式碼範例會 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 物件,而且您需要判斷表單目前正在使用哪一個物件時,通常會使用 屬性。

適用於

另請參閱