,如何检查的形式是开放的,如果打开关闭的形式? [英] How to check if form is open, if open close form?
本文介绍了,如何检查的形式是开放的,如果打开关闭的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何检查,如果一种形式是开放的,如果它是打开关闭的形式?
我尝试以下,测试了一些代码,但它保持说的形式不开,甚至当我知道它是:
的foreach(FORM A在Application.OpenForms)
{
如果(一个是YouLikeHits_Settings)
{
//关于窗体打开
MessageBox.Show(形式开);
中断;
}
//关于格式是不开放...
MessageBox.Show(形式不开);
中断;
}
解决方案
的 包含打开的形式Application.OpenForms。如果该集合中的形式,然后将其打开。否则则不会打开(可能是封闭的)
如果(Application.OpenForms.OfType< YouLikeHits_Settings方式>()任何() )
MessageBox.Show(打开表单);
,否则
MessageBox.Show(形式是不是开);
How do I check if a form is open, and if it is open to close the form?
I tried the following, testing out some code but it keep saying the form is not open even when I know it is:
foreach(Form a in Application.OpenForms)
{
if (a is YouLikeHits_Settings)
{
// About form is open
MessageBox.Show("form open");
break;
}
// About form is not open...
MessageBox.Show("form not open");
break;
}
解决方案
Application.OpenForms contains opened forms. If form in this collection, then it is opened. Otherwise it is not opened (possibly closed).
if (Application.OpenForms.OfType<YouLikeHits_Settings>().Any())
MessageBox.Show("Form is opened");
else
MessageBox.Show("Form is not opened");
这篇关于,如何检查的形式是开放的,如果打开关闭的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文