How Can I Get All My Forms Name in my VB.Net Project?

I Need to Know My Project Forms , and loop on them , could you help me ???
thanks in advance
janartgroupAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

armoghanCommented:
Hi janartgroup,
If it is a MDI application, you can get the open forms from MDI children collection

Cheers!
0
armoghanCommented:
janartgroup,
If you need to find out all the forms which are even not open, and objects even not initialize, use this code

Assembly fa = Assembly.GetExecutingAssembly (); // load the assembly
            Type [] classes = fa.GetTypes(); // get all the classes
            for (int iTypes = 0; iTypes < classes.Length; iTypes++)
            {
                Type bt = classes[iTypes].BaseType;
                if (bt.ToString() == "System.Windows.Forms.Form")
                {
                Console.WriteLine (    classes[iTypes].FullName );
                    // if (form.Localizable)
                    // {
                    // it is Localizable
                    // }
                }
            }  
0
Bob LearnedCommented:
Very nice code, armoghan, but since this is a VB.NET question, some VB code would probably help:

Dim fa As Assembly = Assembly.GetExecutingAssembly()
Dim classes As Type = fa.GetTypes()
Dim iTypes As Integer = 0

While iTypes < classes.Length
 
   Dim bt As Type = classes(iTypes).BaseType

   If bt.ToString() = "System.Windows.Forms.Form" Then
      Console.WriteLine(classes(iTypes).FullName)
   End If

   iTypes += 1

End While


Bob
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

armoghanCommented:
Thanx TheLearnedOne
I actually didnt see the TA :)
It happens when you are answering in C#, Dotnet and VB.NEt area
Thanx for the translation
0
Bob LearnedCommented:
Yeah, I agree, I have to catch myself a lot when working in the C# area, since I my language of choice is VB.

Bob
0
janartgroupAuthor Commented:
well , that is not bad
but i didn't do what i want till now
cause this code allow me to know the forms in my solution through class type , but i need to loop on the forms (as an objects) to open one form from them so i need to make function we pass the form text and the function will open th form by this text

EX:
Private Sub openForm(pFormText as string)
  some code here to compare all forms texts with the pformtext
  when the condition achived we will open the form
End Sub
i can't do it by this solution ,
please it is urgent to me ....
Thanks
0
armoghanCommented:
ohh that is easy. If you are talking about Name field. It is shared. So you can check for it and create the object using Activator. and then can show it

 Dim fa As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
        Dim classes As Type() = fa.GetTypes()
        Dim iTypes As Integer = 0

        While iTypes < classes.Length

            Dim bt As Type = classes(iTypes).BaseType

            If bt.ToString() = "System.Windows.Forms.Form" Then
                Console.WriteLine(classes(iTypes).Name + " ---- " + classes(iTypes).FullName)
                If classes(iTypes).Name.Equals("SomeForm") Then
                    Dim f As System.Windows.Forms.Form
                    f = System.Activator.CreateInstance(classes(iTypes))
                    f.Show()
                End If
            End If
            iTypes += 1
        End While
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.