Iterate through all forms in a project...


Author
Message
StarkMike
StarkMike
Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)
Group: Forum Members
Posts: 436, Visits: 944
I can't seem to find out how to iterate through all the forms in a VB project. Why does this seem so difficult to do? I'm aware of the OpenForms property but I cant really open ALL the forms in my project just to iterate through them.



I can even find out how to reference a form if i have the name:

dim frm as form = Forms("Form1")



Anybody got any advice?
Replies
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Well, I think that its more complicated because everything isn't an object....until its been instantiated. Until then, it's a type (System.Type). I.e. you might have a form EmployeeForm. Really this is a Type, not an object. It's not an object until it's been instantiated. E.g. lets say you have a constructor that accepts an Employee ID, then loads that employees record into the form. Then you allow the user to open the form multiple times, for like five employees. Then you have 5 objects of the type EmployeeForm. Then you can iterate through them, using Application.OpenForms() to access these.



I'm still trying to figure out Reflection myself, so I'm still a bit confused as well. Also, since I need to obfuscate my assemblies, I'm more limited using reflection than I'd like.
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
If you are using an MDI environment then you can use the forms collection of the MDIClient as shown below.

Dim loForm As System.Windows.Forms.Form
Dim llReturn As Boolean = False
For Each loForm In MyMDI.MdiChildren
   If loForm.GetType() Is FormType
      llReturn = True
     
      '-- Place your code here
   End If   
Next
Return llReturn
End Function

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search