如果打开格式,如何检查表格是否打开?

Edw*_*res 5 c# winforms form-control

如何检查表单是否已打开,以及表单是否已打开以关闭表单?

我尝试了下面的代码,测试了一些代码,但它仍然表示,即使我知道它是:

 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;
 }
Run Code Online (Sandbox Code Playgroud)

Ser*_*kiy 15

Application.OpenForms包含打开的表单.如果此集合中有表单,则会打开它.否则它不会打开(可能已关闭).

if (Application.OpenForms.OfType<YouLikeHits_Settings>().Any())
    MessageBox.Show("Form is opened");
else
    MessageBox.Show("Form is not opened");
Run Code Online (Sandbox Code Playgroud)