1、判断子窗体是否被打开
public bool checkchildFrmExist(string childFrmName)
{
foreach (Form childFrm in this.MdiChildren)
{
if (childFrm.Text.ToString() == childFrmName)
{
if (childFrm.WindowState == FormWindowState.Minimized)
{
childFrm.WindowState = FormWindowState.Normal;
}
childFrm.Activate();
return true;
}
}
return false;
}
2、子窗体调用
private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
{
if (checkchildFrmExist("用户管理") == true) { return; }
Frm_userAdd form1 = new Frm_userAdd();
form1.MdiParent = this;
form1.Show();
form1.WindowState = FormWindowState.Maximized;
}
好像没有,不过你可以在窗体追加一个Public的属性,在活动和非活动的事件中,对它的值作修改
也可以直接在父窗体调用事件
例如
bool IsForm4Actived = false;
private void button1_Click(object sender, EventArgs e)
{
Form4 f= new Form4();
f.MdiParent = this;
f.Activated += new EventHandler(f_Activated);
f.Deactivate += new EventHandler(f_Deactivate);
f.Show();
}
void f_Deactivate(object sender, EventArgs e)
{
IsForm4Actived = false;
}
void f_Activated(object sender, EventArgs e)
{
IsForm4Actived = true;
}
frm就是你的子窗体,在frm.show()之后添加此句就行了
frm.dock
=
dockstyle.fill;
我来了。
没有办法了,不过可以用个public static变量在父窗体中存当前被激活的窗体。
class Form1 : Form
{
public static CurWin = null;
}
当子窗体激活时 Form1.CurWin = this;