为“新建”菜单项创建 Click 事件处理程序。有关创建事件处理程序的更多信息,请参见在 Windows 窗体设计器上创建事件处理程序。
插入类似于以下代码的代码,以便在用户单击“新建”菜单项时创建新的 MDI 子窗体(在下面的示例中,事件处理程序处理 MenuItem2 的 Click 事件。请注意,您的“新建”菜单项可能不是 MenuItem2,这取决于应用程序结构的具体情况。)。
' Visual Basic
Protected Sub MDIChildNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Dim NewMDIChild As New Form2()
'Set the Parent Form of the Child window.
NewMDIChild.MdiParent = Me
'Display the new form.
NewMDIChild.Show()
End Sub
// C#
protected void MDIChildNew_Click(object sender, System.EventArgs e){
Form2 newMDIChild = new Form2();
// Set the Parent Form of the Child window.
newMDIChild.MdiParent = this;
// Display the new form.
newMDIChild.Show();
}
// C++
private:
System::Void menuItem2_Click(System::Object * sender,
System::EventArgs * e)
{
Form2 *newMDIChild = new Form2();
// Set the Parent Form of the Child window.
newMDIChild->MdiParent = this;
// Display the new form.
newMDIChild->Show();
}
在 Visual C++ 中,在 Form1.h 的上面添加以下 #include 指令: