日期:2014-05-18 浏览次数:21095 次
/* -----------frmMian----------- */ private frmS fs = null; private frmW fw = null; private void button1_Click(object sender, EventArgs e) { frmS f = new frmS(); fs = f; f.Show(); frmW ff = new frmW(); fw = ff; ff.Show(); } private void button3_Click(object sender, EventArgs e) { if (fs != null) { fs.Close(); fs = null; } } /* --------frmW------- */ private frmS fs = null; private void button1_Click(object sender, EventArgs e) { frmS f = new frmS(); fs = f; f.Show(); this.Close(); }
------解决方案--------------------
private void frmMain_Load(object sender, EventArgs e)
{
frmS fs = new frmS();
fs.MaximizeBox = true;
fs.MdiParent = this;
fs.Show();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
frmW fw = new frmW();
fw.MdiParent = this.MdiParent ;
fw.Show();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
frmS fs = new frmS();
fs.MdiParent = this.MdiParent ;
fs.Show();
}
------解决方案--------------------
我的这个可以通过,而且可以防止打开多个窗体,如果已经打开,就激活他
public partial class frmMain : Form { public frmMain() { InitializeComponent(); } private void 登录ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (Form form in Application.OpenForms) { if (form.Name == "frmLogin") { form.Activate(); form.WindowState = FormWindowState.Maximized; return; } } frmLogin login = new frmLogin(); login.MdiParent = this; login.WindowState = FormWindowState.Maximized; login.Show(); } private void 日志ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (Form form in Application.OpenForms) { if (form.Text == "frmLogInfo") { form.Activate(); return; } } frmLogInfo log = new frmLogInfo(); log.MdiParent = this; log.WindowState = FormWindowState.Maximized; log.Show(); } private void frmMain_Load(object sender, EventArgs e) { frmLogin login = new frmLogin(); login.WindowState = FormWindowState.Maximized; login.MdiParent = this; login.Show(); } }