MainMenu.GetForm メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As MainMenu Dim returnValue As Form returnValue = instance.GetForm
このコントロールのコンテナである Form。MainMenu が現在フォームにホストされていない場合は null 参照 (Visual Basic では Nothing) を返します。

このプロパティを使用すると、特定の MainMenu の親がフォームかどうかを確認できます。このプロパティは、通常、複数の MainMenu オブジェクトがフォーム上で使用されていて、現在フォームで使用されているオブジェクトがどれかを確認する必要がある場合に使用されます。

GetForm メソッドを使用して、MainMenu の現在の親がそのフォームかどうかを判断するコード例を次に示します。このコード例で呼び出されている GetForm が null 参照 (Visual Basic では Nothing) 値を返さない場合、このコードは、CloneMenu メソッドを使用して、MainMenu のメニュー構造のクローンを作成します。次に、MainMenu の新しいコピーの RightToLeft プロパティを true に設定し、テキストが右から左に表示される言語に対応した MainMenu を作成します。この例では、mainMenu1 という名前の MainMenu が作成されている必要があります。
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
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; } }
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.set_RightToLeft(get_RightToLeft().Yes); } } //CloneMyMenu

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- MainMenu.GetForm メソッドのページへのリンク