Close all open forms except the main menu in C#

前端 未结 8 1845
终归单人心
终归单人心 2020-12-16 14:27

Trying to close all forms except for the main menu using

FormCollection formsList = Application.OpenForms;

with a foreach loop and saying,

8条回答
  •  执念已碎
    2020-12-16 15:12

    To Close all forms :

            for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
            {
                if (Application.OpenForms[i].Name != "Menu")
                    Application.OpenForms[i].Close();
            }
    

提交回复
热议问题