MDI窗体,子窗体在父窗体中最大化,如果子窗体已经打开则显示,不重复打开窗体
转自:http://virusswb.cnblogs.com/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication4
{
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();
}
}
}
MDI窗体,子窗体在父窗体中最大化,如果子窗体已经打开则显示,不重复打开窗体,当然可以使用单件模式来实现或者使用多线程里面的互斥体技术。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication4
{
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();
}
}
}
MDI窗体,子窗体在父窗体中最大化,如果子窗体已经打开则显示,不重复打开窗体,当然可以使用单件模式来实现或者使用多线程里面的互斥体技术。