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

このコントロールのコンテナーである FormMainMenu が現在フォームにホストされていない場合は null を返します。

次のコード例では、メソッドを GetForm 使用して、 MainMenu フォームに現在親になっているかどうかを判断します。 コードGetForm例の呼び出しが返nullされない場合、コードはメソッドを使用してメニュー構造をMainMenuCloneMenu複製します。 次に、コードは、右から左のテキストをサポートする言語に使用できるプロパティをMainMenu作成する新しいコピーMainMenuでプロパティを true に設定RightToLeftします。 この例では、名前が付mainMenu1いたMainMenu作成済みである必要があります。

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 オブジェクトが使用されており、フォームで現在使用されているオブジェクトを決定する必要がある場合に使用されます。

適用対象

こちらもご覧ください