我需要能够关闭一个表单并让它关闭除开关板之外的所有其他表单。我尝试使用此代码,但它也关闭了 frmSwitch,即使我尝试对其进行编码以关闭除此之外的所有内容。我哪里做错了?我应该使用表格的实际名称对吗?
Form[] forms = Application.OpenForms.Cast<Form>().ToArray();
foreach (Form thisForm in forms)
{
if (thisForm.Name != "frmSwitch") thisForm.Close();
}