MainMenu.GetForm 方法
定义
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 Form that is the container for this control. 如果 MainMenu 当前没有在窗体上寄宿,则返回 null。Returns null if the MainMenu is not currently hosted on a form.
示例
下面的代码示例使用 GetForm 方法来确定 MainMenu 当前是否为窗体的父级。The following code example uses the GetForm method to determine if a MainMenu is currently parented to the form. 如果代码示例中的调用 GetForm 未返回 null ,则代码将使用方法克隆的菜单结构 MainMenu CloneMenu 。If the call in the example code to GetForm does not return null, the code then clones the menu structure of the MainMenu using the CloneMenu method. 然后,代码将的 RightToLeft 新副本上的属性设置为 true, MainMenu 以创建 MainMenu 可用于支持从右向左文本的语言的。The code then sets the RightToLeft property to true on the new copy of the MainMenu to create a MainMenu that can be used for languages that support right to left text. 此示例要求您创建一个名为的 MainMenu mainMenu1 。This example requires that you have a MainMenu created that is named 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 是否为窗体的父级。This property enables you to determine if a specific MainMenu is parented to a form. 当 MainMenu 窗体上使用多个对象,并且需要确定窗体当前正在使用哪个对象时,通常会使用属性。The property is typically used when multiple MainMenu objects are being used on a form and you need to determine which one is currently being used by a form.