且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

,如何检查的形式是开放的,如果打开关闭的形式?

更新时间:2023-11-28 11:50:22

包含打开的形式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");