MDI窗体,子窗体在父窗体中最大化,如果子窗体已经打开则显示,不重复打开窗体
2008-04-17 13:11 Virus-BeautyCode 阅读(3962) 评论(0) 编辑 收藏 举报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();
}
}
}
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窗体,子窗体在父窗体中最大化,如果子窗体已经打开则显示,不重复打开窗体,当然可以使用单件模式来实现或者使用多线程里面的互斥体技术。
互斥体技术见我的另一篇博客,地址如下:
http://www.cnblogs.com/virusswb/archive/2008/03/26/1122480.html