MainMenu.GetForm 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
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这是此控件的容器。 如果窗体上当前未托管,MainMenu则返回null。
示例
下面的代码示例使用 GetForm 该方法来确定当前是否 MainMenu 为窗体添加父级。 如果示例代码GetForm中的调用不返回null,则代码将克隆使用CloneMenu该方法的MainMenu菜单结构。 然后,代码将 RightToLeft 属性设置为 true,以便在新副本 MainMenu 中创建一个 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 对象并且需要确定窗体当前正在使用的对象时,通常会使用该属性。