📜  cs 在重新打开时关闭打开的表单 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:11.145000             🧑  作者: Mango

代码示例1
// Look through all open forms to see if there is already a Form2 open.
// If it is, Close it. This prevents the user from (purposely) having 5 of the same forms open.
// If you try to cycle through open forms after closing one, it crashes, 
//     because it edits the list of forms while cycling through it
// This is why it is converted into a list of forms first.
foreach (Form frm in Application.OpenForms.Cast
().ToList()) { if (frm.Name == "Form2") { frm.Close(); } }