public Form1()
{
InitializeComponent();
//将Form1设置为MDI窗体,当然在Form1的IsMdiContainer属性页可以设置
this.IsMdiContainer = true;
}
private void tsmiOpenWindow_Click(object sender, EventArgs e)
{
FrmChildren child = FrmChildren.GetWindow();//调用方法
child.MdiParent = this;//设置child的父窗体为当前窗体
child.Show();
}
public partial class FrmChildren : Form
{
private FrmChildren() //由 public FrmChildren改为 private FrmChildren
{
InitializeComponent();
}
static FrmChildren fc = null; 创建一个静态对象
public static FrmChildren GetWindow()
{ //当子窗体没有开启或者已经释放。就可以创建新窗体
if (fc==null||fc.IsDisposed)
{
fc = new FrmChildren();
}
return fc;
}
}
private void tsmiOpenWindow_Click(object sender, EventArgs e)
{
#region 方法二Application收集打开的窗体,用索引器来寻找,就是窗体的Name属性
//方法二.如果没有Name为FrmChildren的子船体,实例化创建。和之前的正规做法没有什么差别,只是多了判断。
if (Application.OpenForms["FrmChildren"] == null)
{
FrmChildren child = new FrmChildren();
child.MdiParent = this;
child.Show();
}
else//有Name为FrmChildren的子船体,就直接show()
{
Application.OpenForms["FrmChildren"].Show();
}
#endregion
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有