C# enumerate all open winforms

zattz
zattz used Ask the Experts™
on
Hi

How can I get a reference to all the open forms in my application? I want to change their positions.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Create a base form and inherit other form from base form.
Other way, you can pass it through constructor of each form;
The easiest way to do this is to enumerate thru
Application.OpenForms.
This returns a FormCollection of all open forms in your application.
On any suitable event write below lines of code
FormCollection collections = Application.OpenForms;
foreach (Form f in collections)
{
  f.Location = new Point(10, 10); // set you location here
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial