Close all open forms except the main menu in C#

前端 未结 8 1890
终归单人心
终归单人心 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:21

    as the form collection is updating for every iteration. When you close a form, it is removed from the form collection. it's like removing a object from memory while it is using .

提交回复
热议问题