花了我一上午的时间,找来找去找不到答案,又是急性子,只好自己动手了,见笑,也请大家多提意见,谢了。
parent.cs
————————————————————
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
namespace testagain
{
/// <summary>
/// summary description for parent.
/// </summary>
public class parent : system.windows.forms.form
{
private system.windows.forms.mainmenu mainmenu1;
private system.windows.forms.menuitem m_filemenu;
private system.windows.forms.menuitem m_openfile;
private system.windows.forms.menuitem m_close;
private system.windows.forms.mdiclient mdiclient1;
private system.windows.forms.menuitem menuitem1;
/// <summary>
/// required designer variable.
/// </summary>
private system.componentmodel.container components = null;
public parent()
{
//
// required for windows form designer support
//
initializecomponent();
testform f_test = new testform(this);
f_test.show();
//
// todo: add any constructor code after initializecomponent call
//
}
public static void main()
{
application.run(new parent());
}
/// <summary>
/// clean up any resources being used.
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}
#region windows form designer generated code
/// <summary>
/// required method for designer support – do not modify
/// the contents of this method with the code editor.
/// </summary>
private void initializecomponent()
{
this.mainmenu1 = new system.windows.forms.mainmenu();
this.m_filemenu = new system.windows.forms.menuitem();
this.m_openfile = new system.windows.forms.menuitem();
this.m_close = new system.windows.forms.menuitem();
this.menuitem1 = new system.windows.forms.menuitem();
this.mdiclient1 = new system.windows.forms.mdiclient();
this.suspendlayout();
//
// mainmenu1
//
this.mainmenu1.menuitems.addrange(new system.windows.forms.menuitem[] {
this.m_filemenu,
this.menuitem1});
//
// m_filemenu
//
this.m_filemenu.index = 0;
this.m_filemenu.menuitems.addrange(new system.windows.forms.menuitem[] {
this.m_openfile,
this.m_close});
this.m_filemenu.text = "文件(&f)";
//
// m_openfile
//
this.m_openfile.index = 0;
this.m_openfile.shortcut = system.windows.forms.shortcut.ctrlo;
this.m_openfile.text = "dns探测";
this.m_openfile.click += new system.eventhandler(this.m_openfile_click);
//
// m_close
//
this.m_close.index = 1;
this.m_close.shortcut = system.windows.forms.shortcut.ctrlx;
this.m_close.text = "关闭";
this.m_close.click += new system.eventhandler(this.m_close_click);
//
// menuitem1
//
this.menuitem1.index = 1;
this.menuitem1.text = "关于…(&a)";
this.menuitem1.click += new system.eventhandler(this.menuitem1_click);
//
// mdiclient1
//
this.mdiclient1.dock = system.windows.forms.dockstyle.fill;
this.mdiclient1.name = "mdiclient1";
this.mdiclient1.tabindex = 0;
//
// parent
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(536, 309);
this.controls.addrange(new system.windows.forms.control[] {
this.mdiclient1});
this.ismdicontainer = true;
this.menu = this.mainmenu1;
this.name = "parent";
this.startposition = system.windows.forms.formstartposition.centerscreen;
this.text = "mdi窗体操作演示_父窗体";
this.resumelayout(false);
}
#endregion
private void menuitem1_click(object sender, system.eventargs e)
{
form f_activeform = this.activemdichild;
if (f_activeform != null)
{
if (f_activeform.name != null && f_activeform.name != "parent")
{
f_activeform.close();
}
}
child child_form = new child(this);
child_form.show();
}
private void m_close_click(object sender, system.eventargs e)
{
this.close();
}
private void m_openfile_click(object sender, system.eventargs e)
{
form f_activeform = this.activemdichild;
if (f_activeform != null)
{
if (f_activeform.name != null && f_activeform.name != "parent")
{
f_activeform.close();
}
}
testform f_test = new testform(this);
f_test.show();
}
}
}
