Answered by:
c# window Forms

Question
-
Hi ,
I have a requirement to retrieve "Form Name" and Form title [Text Property ] of all the forms present in window application
upon the launch of "EXE",i.e,during runtime
Someone please tell me how to do that .I tried this
List<string> GetForms()
{
var types = Assembly.LoadFile(textBox2.Text).GetTypes();
List<string> FormsCol = new List<string>();
foreach( Type t in types)
{
if (t.BaseType.ToString() == "System.Windows.Forms.Form")
FormsCol.Add(t.FullName);
}
return FormsCol;
}By this,However i am only able to fetch Form names..an i need text / title also.
Answers
-
Try this Code
Type formType = typeof(Form); foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()) if (formType.IsAssignableFrom(type)) { MessageBox.Show(type.Name); }
Happy Coding, RDRaja
- Marked as answer by Eason_H Monday, September 30, 2013 5:57 AM
All replies
-
If all your forms are open(not hidden), you can use Application.OpenForms property. It will return a FormsCollection. Then you can iterate through these and get all form properties you need.
Well, if some of the forms are hidden, this link should help.
Hope this helps.
Cheers!
-
Try this Code
Type formType = typeof(Form); foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()) if (formType.IsAssignableFrom(type)) { MessageBox.Show(type.Name); }
Happy Coding, RDRaja
- Marked as answer by Eason_H Monday, September 30, 2013 5:57 AM