int count = Application::OpenForms->Count; if (count > 1) { array<Form^>^ forms = gcnew array<Form^>(count); int i = 0; for each (Form^ form in Application::OpenForms) forms[i++] = form; for (i = 0; i < count; i++) if (forms[i]->Name != L"Form1") forms[i]->Close(); delete[] forms; }