Click here to Skip to main content
15,610,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all i have created small program using 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
end sub 

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

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

Simple, replace the MsgBox Line with
Share this answer
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.
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.

Share this answer
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
            End If

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