我做了一个MDI的WinForm应用程序,链接access数据库进行数据处理,每个子窗体都有不同的数据和计算功能。我是设置一个窗体为父窗体,然后在应用程序中添加了多个窗体程序,在显示每个窗体程序之前都设置它的MdiParent属性为前面的父窗体,再在父窗体中设置菜单,单击菜单项会打开相应的子窗体。
我的问题是每个子窗体的运行都没有问题,可是当我打开一个子窗体是,再打开另一个子窗体,那前一个窗体就会自动关闭!这是为什么啊?高手指教指教!谢谢了!
我的问题是每个子窗体的运行都没有问题,可是当我打开一个子窗体是,再打开另一个子窗体,那前一个窗体就会自动关闭!这是为什么啊?高手指教指教!谢谢了!
{
public MainWindow()
{
InitializeComponent();
} File.NewPro newpro;
Data.DLeftLine leftline;
Data.LefLinCheck leflincheck;
LineSurvey.CoorCalcu coorcalcu;
Data.ChainLine chainline;
File.OpenPro openpro;
Data.VerticalLine verticalline;
public static string tablestr; private void NewProMenu_Click(object sender, EventArgs e)
{
if (newpro == null || newpro.IsDisposed)
{
newpro = new URTESS.File.NewPro();
for (int x = 0; x < this.MdiChildren.Length; x++)
{
Form tempChild = (Form)this.MdiChildren[x];
tempChild.Close();
}
newpro.MdiParent = this;
newpro.Show();
}
}
private void LefLinDesign_Click(object sender, EventArgs e)
{
leftline = new URTESS.Data.DLeftLine();
tablestr = "左线";
for (int x = 0; x < this.MdiChildren.Length; x++)
{
Form tempChild = (Form)this.MdiChildren[x];
tempChild.Close();
}
leftline.MdiParent = this;
leftline.Show();
}
private void LefLinCheck_Click(object sender, EventArgs e)
{
URTESS.Class.LeftCheckCalcu lefchecal = new URTESS.Class.LeftCheckCalcu();
lefchecal.CheckCalcu("tb_LeftLine");
tablestr = "左线";
leflincheck = new URTESS.Data.LefLinCheck();
for (int x = 0; x < this.MdiChildren.Length; x++)
{
Form tempChild = (Form)this.MdiChildren[x];
tempChild.Close();
}
leflincheck.MdiParent = this;
leflincheck.Text = "左线参数复核表";
leflincheck.Show();
}
private void CooCalcu_Click(object sender, EventArgs e)
{
coorcalcu = new URTESS.LineSurvey.CoorCalcu();
for (int x = 0; x < this.MdiChildren.Length; x++)
{
Form tempChild = (Form)this.MdiChildren[x];
tempChild.Close();
}
coorcalcu.MdiParent = this;
coorcalcu.Show(); }
private void ChainLine_Click(object sender, EventArgs e)
{
chainline = new URTESS.Data.ChainLine();
for (int x = 0; x < this.MdiChildren.Length; x++)
{
Form tempChild = (Form)this.MdiChildren[x];
tempChild.Close();
}
chainline.MdiParent = this;
chainline.Show();
} private void RetLinDesign_Click(object sender, EventArgs e)
{
leftline = new URTESS.Data.DLeftLine();
leftline.Text = "右线参数设计表";
tablestr = "右线";
for (int x = 0; x < this.MdiChildren.Length; x++)
{
Form tempChild = (Form)this.MdiChildren[x];
tempChild.Close();
}
leftline.MdiParent = this;
leftline.Show();
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WinForm
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.MdiParent = this;
form1.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.MdiParent = this;
form2.Show();
}
}
}
当单击不同的按钮时就相识不同的窗体!