priavte UsForm sForm=null;按钮代码
if (sForm != null)
{
sForm.Show();
sForm.Focus();
}
else
{
sForm = new UsForm();
sForm.MdiParent = this;
sForm.Show();
sForm.Focus();
}
解释一下。UsForm,是我调用的CS.dll文件下的。现在是我在MDI窗体Main下一个按钮里调用的,现在是不会同时打开二个实例,可我关闭实例,再次运行,就没有任何反映,请帮忙啊
if (sForm != null)
{
sForm.Show();
sForm.Focus();
}
else
{
sForm = new UsForm();
sForm.MdiParent = this;
sForm.Show();
sForm.Focus();
}
解释一下。UsForm,是我调用的CS.dll文件下的。现在是我在MDI窗体Main下一个按钮里调用的,现在是不会同时打开二个实例,可我关闭实例,再次运行,就没有任何反映,请帮忙啊
if (MUpPassForm == null)
{
ShowUpPassForm();
}
else
{
if (MUpPassForm.Text.ToString().Trim() == "")
{
ShowUpPassForm();
}
}
private void ShowUpPassForm()
{
MUpPassForm = new UpPassForm();
MUpPassForm.MdiParent = this;
MUpPassForm.Show();
MUpPassForm.Focus();
}
就可以了,哪这样的话,也没得啥子意思啊,为什么 MUpPassForm !=null 我直接让他show会有错误啊
if (!sForm.Visible)
{
sForm.Focus();
}
else
{
sForm = new UsForm();
sForm.MdiParent = this;
sForm.Show();
sForm.Focus();
}
foreach(Form f in this.MdiChildren)
{
if(f is UsForm)
{
sForm = (UsForm)f;
break;
}
}
if(sForm != null)
{
sForm.Show();
sForm.Focus();
}
else
{
sForm = new UsForm();
sForm.MdiParent = this;
sForm.Show();
sForm.Focus();
}
试试这样
foreach(Form f in this.MdiChildren)
{
if(f is MyChildForm)
{
// found it
childForm = (MyChildForm) f;
break;
}
}
if( childForm != null)
{
childForm.Show();
childForm.Focus();
}
else
{
childForm = new MyChildForm();
childForm.MdiParent = this;
childForm.Show();
childForm.Focus();
}
这个简单的修改了一下我的窗体名而已反正第二次打开后就没有任何显示
以后的代码是查询当前的MdiChildren集中,如果没有的话,当然也不会修改其值
不要设为全局的,定义为函数的局部变量
foreach(Form f in this.MdiChildren)
{
if(f is UsForm)
{
sForm = (UsForm)f;
break;
}
}if (sForm != null)
{
sForm.Show();
sForm.Focus();
}
else
{
sForm = new UsForm();
sForm.MdiParent = this;
sForm.Show();
sForm.Focus();
}
private UsForm sForm = null;
删除,然后在你进行判断的时候,
在函数内部加上
UsForm sForm = null;例如:
//Add a document
private void AddDocument()
{
// MyChildForm is the one I'm looking for
Document childForm = null;
foreach(Form f in this.MdiChildren)
{
if(f is Document)
{
// found it
childForm = (Document) f;
break;
}
}
if( childForm != null)
{
childForm.Show();
childForm.Focus();
}
else
{
childForm = new Document("Document ");
childForm.MdiParent = this;
childForm.Show();
childForm.Focus();
}
}
另,大哥,foreach(Form f in this.MdiChildren)
{
if(f is Document)
{
// found it
childForm = (Document) f;
break;
}
}
这些代码,我感觉没什么用嘛,也就是找到他也没有什么有用的吧
我不用QQ,如果有什么问题的话,发邮件给我 [email protected]