VB.NET: How to get the good old Forms Collection
Remember the good old Forms collection in VB 6.0. How easy it was to enumerate through the Forms that were loaded. In .NET we don't have any such collection.
In .NET this can be achieved by adding a simple Class with a Shared member.
VB Code:
Public Class FormsCollection
Public Shared Forms As ArrayList = New ArrayList
End Class
Now in the constructor of all the Forms write
VB Code:
FormsCollection.Forms.Add(Me)
This will add the Forms to the collection whenever they are created in the memory.
Now to loop through the collection we can use
VB Code:
For Each f As Form In FormsCollection.Forms
'rest of code here
Next
Remember when you close the Form you need to remove the Form from the Collection using
VB Code:
FormsCollection.Forms.Remove(Me)
Re: VB.NET: How to get the good old Forms Collection
The above post is good for .NET 1.1 or earlier. VB 2005 has got the Forms collection again.
Microsoft has retained lot of functionality from good old VB 6 in VB 2005. Now you do not have to write code for having a Forms Collection, MY object in VB 2005 has got it for you. My.Application.OpenForms property can be used to iterate through all loaded and visible forms in the current application.
Re: VB.NET: How to get the good old Forms Collection
how to do this in visual c++ .net 2003?
i'm kinda new to vc++ and i have this impression that whatever can be done in vb.net can also be done in vc++.net.
do i have to put the line
VB Code:
FormsCollection.Forms.Add(Me)
in the Load event of the Form?
also, how do i make a class in vc++ with a shared member like the one you listed above? (this is probably not the right place to ask this question but someone who's knowledgeable in vc++ and vb might stumble upon this thread).
i hope someone there's someone out there who could help me. this is the closest i got to finding a solution to looping through opened forms in .NET 2003, and it's in VB. :(
Re: VB.NET: How to get the good old Forms Collection
I don't think I'll be of any help here. I don't have any experience in VC++.
You can probably ask this question on Codeguru
Re: VB.NET: How to get the good old Forms Collection
The C++ and C# equivalents of 'Me' and 'Shared' are 'this' and 'static'.