【文件属性】:
文件名称:c# 防止 打开 重复子窗体
文件大小:1KB
文件格式:TXT
更新时间:2013-08-19 10:57:19
c# mdi 父窗体 子窗体
bool cwExists = false; //子窗体是否已经存在
foreach (System.Windows.Forms.Form ff in parentWindow.MdiChildren)
{
//把活动的子窗体最小化
ff.WindowState = System.Windows.Forms.FormWindowState.Minimized;
//如果是要打开的子窗体,激活并还原子窗体
if (ff.Name == childrenWindow.Name)
{
ff.Activate();
//ff.Size = ff.Parent.Size;
ff.WindowState = System.Windows.Forms.FormWindowState.Normal;
ff.Left = ff.Top = 0; //打开位置居于左上角
cwExists = true; //子窗体存在
}
}
//子窗体不存在,打开子窗体
if (cwExists == false)
{
parentWindow.IsMdiContainer = true;
childrenWindow.MdiParent = parentWindow;
childrenWindow.WindowState = System.Windows.Forms.FormWindowState.Normal;
childrenWindow.Show();
childrenWindow.Left = childrenWindow.Top = 0; //打开位置居于左上角
}
网友评论
- 额 知道了 在哪看过
- 一个TXT文件,在网上抄的吧