开发者

How to get the list of forms in VS2008 C# project?

I want to get a list of all the for开发者_如何转开发ms in the project i am running a form from .

Suppose i am running a project which has 4 forms 1.Form1 2.Form2 3.Form3 4.Form4

and i want to retrieve the list of them for further direction which form to direct to


Do you mean:

  1. Design-time?
  2. Run-time?

If run-time, do you mean:

  1. All forms defined in the project?
  2. All open forms

If at Design-time, then I don't know.

If you mean at run-time, and you want all forms declared, you need to resort to reflection. Iterate through all types in your assembly(/ies) and find all types inheriting from the Form class.

Something like this would do:

Type formType = typeof(Form);
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
   if (formType.IsAssignableFrom(type))
   {
       // type is a Form
   }

If you mean at run-time, and you want all open forms, you can use Application.OpenForms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜