-2

i need to display list of opened forms in windows application(windows forms) c#. can anyone tell me how to store open form names and display it .... i need display like below

e.g

open form names

  • form1
  • form2

how to do it. can anyone help me...

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
Happy
  • 63
  • 2
  • 8

3 Answers3

5

Use Application.OpenForms collection:

var names = Application.OpenForms.Cast<Form>().Select(f => f.Name);

If you want types of opened forms, then select f.GetType().Name

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
  • its showing like this System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Windows.Forms.Form,System.String] – Happy Dec 15 '13 at 17:10
  • @Happy yes, that will be collection. You can create list of names with `names.ToList()` or you can create string with all names `String.Join(Environment.NewLine, names)` – Sergey Berezovskiy Dec 15 '13 at 17:16
0

If you want system wide you can use EnumWindows to get all top level windows, your question isn't clear about exactly what you're after.

How can I get EnumWindows to list all windows?

Community
  • 1
  • 1
paulm
  • 5,629
  • 7
  • 47
  • 70
-3

var names = Application.OpenForms.Cast().Select(f => f.Name);

Jana Mani
  • 30
  • 1
  • 4
  • 1
    Looks like a poorly formatted duplicate of Sergey's answer. I wonder why this two-year-old question recently had this answer added, and then three days later selected as correct. – James Oct 05 '15 at 08:36