Mdi不重复打开子窗体的问题,帮我看一段代码
有一个MDI窗提,为了防止重复打开相同的子窗体,我是这样处理的,代码如下:
这样处理也是没问题的。
private XFrmCompany xFrmCompany = null;
private void barButtonItem29_ItemClick(object sender,
DevExpress.XtraBars.ItemClickEventArgs e)
{
if ((xFrmCompany == null) || xFrmCompany.IsDisposed)
{
xFrmCompany = new XFrmCompany();
xFrmCompany.MdiParent = this;
xFrmCompany.Show();
MessageBox.Show(xFrmCompany.IsDisposed.ToString());
}
else
{
xFrmCompany.Activate();
}
}
=======================================================
由于子窗体太多,我于是确定把XFrmCompany作为参数传递过去,代码如下:
private XFrmCompany xFrmCompany = null;
private void ShowChildForm(DevExpress.XtraEditors.XtraForm childForm, string className)
{
if ((childForm == null) || (childForm.IsDisposed))
{
Type classType = Type.GetType(className);
if (classType != null)
{
childForm = (DevExpress.XtraEditors.XtraForm)Activator.CreateInstance(classType);
childForm.MdiParent = this;
childForm.Show();
}
}
else
{
childForm.Activate();
}
}
private void barButtonItem29_ItemClick(object sender, DevExpress.XtraBars.I