共用方式為


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 A 就是這個控制的容器。 如果目前MainMenu未在表單上存放,則可回傳null

範例

以下程式碼範例使用該 GetForm 方法來判斷 a MainMenu 目前是否被子層管理為表單。 如果範例程式碼GetForm中的呼叫未回傳 null,程式碼就會複製使用 該MainMenuCloneMenu方法的選單結構。 程式碼接著在新的 版本MainMenu上將屬性設RightToLeft為 true,以建立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 物件,且你需要判斷表單目前正在使用哪一個物件。

適用於

另請參閱