Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2004-11-29
7
Medium Priority
?
813 Views
Last Modified: 2010-04-23
I Need to Know My Project Forms , and loop on them , could you help me ???
thanks in advance
0
Comment
Question by:janartgroup
  • 4
  • 2
7 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12702927
Hi janartgroup,
If it is a MDI application, you can get the open forms from MDI children collection

Cheers!
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12702957
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12704804
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Expert Comment

by:armoghan
ID: 12704932
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12704986
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
 

Author Comment

by:janartgroup
ID: 12713497
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
 
LVL 18

Accepted Solution

by:
armoghan earned 800 total points
ID: 12713879
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question