Click here to Skip to main content
16,018,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all i have created small program using vb.net 2008 i want to get all form names from project solution at run time please give me code.
i think code look like this



private sub proshowformnames()
  For Each FRM As Form In Application.OpenForms
     MsgBox(FRM.Name)
  Next
end sub 



above code is runing perfectly
i need like this close form names at runtime

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 8-May-19 0:53am
v2

Simple, replace the MsgBox Line with
FRM.Close()
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Apr-11 14:48pm    
This is correct, my 5, but... how about main form?
See my answer for two important items.
--SA
Just a warning for you: I'm not sure you really need Form.Name. During run-time, this property means nothing; it's only useful for Designer. If you do it just for learning purposes, that's fine.

Thought you better know this.

Also, please be advised that closing the form will eventually close the application, may be even before you traverse all forms (the order of operation is not defined). You may want to check each from to be your main form and skip the main form.

—SA
 
Share this answer
 
v2
VB
Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
        Dim types As Type() = myAssembly.GetTypes()
        For Each myType As Object In types

            If myType.BaseType.FullName.ToString.ToUpper = "SYSTEM.WINDOWS.FORMS.FORM" Then
                MessageBox.Show(myType.Name)
            End If
        Next




Arabicturgeman
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900