This little bit of code implements A true VB6 style Forms Collection. All you have to do to implement it is inherit from FormEx instead of System.Windows.Forms.Form and if you want your Form to be in the collection and thus be global through the static/shared FormsExCollection you pass a key to the constructor when you create your Form in the Sub Main or where evere set it equal to a new FormEx (New FormEx("FormsKey")) after thats you can access the Form from anywhere in code by simply typing FormEx.Forms("FormsKey").Member.Member()

This is a lite version of the one I am making in C# and there are some issues to be aware of like i don't do anything about the developer adding a key twice. And the collection only has limetted Collection behavior. The C# one is allot better because it is the vesion I am actually developing but I thought you guys might want to have a look at this and it might be useful to somebody even in the lite version. the C# version is in the C# forum if anyone wants to look it.

Oh! I have not done any tests with this one I just typed it out in the forum, so it might have a bug or two but I don't think it does the code is fairly simple the only thing I'm not sure about is the Item property because it's been a long time since I have coded in vb.net. Should work though.

VB Code:
  1. Public Class FormEx
  2.     Inherits System.Windows.Forms.Form
  3.  
  4.     Public Sub New()
  5.         MyBase.New()
  6.     End Sub
  7.  
  8.     Public Sub New(ByVal key As String)
  9.         MyBase.New()
  10.         _formsex.Add(Me, key)
  11.     End Sub
  12.  
  13.     Private Shared _formsex As FormsExCollection = New FormsExCollection()
  14.     Public Shared Property Forms() As FormsExCollection
  15.         Get
  16.             Return _formsex
  17.         End Get
  18.         Set(ByVal Value As FormsExCollection)
  19.             _formsex = Value
  20.         End Set
  21.     End Property
  22.  
  23.     Public Overloads Overrides Sub Dispose()
  24.         If _formsex.Contains(Me) Then _formsex.Remove(Me)
  25.         MyBase.Dispose(True)
  26.         GC.SuppressFinalize(True)
  27.     End Sub
  28. End Class
  29.  
  30. Public Class FormsExCollection
  31.     Private _keys As System.Collections.ArrayList = New System.Collections.ArrayList()
  32.     Private _formsex As System.Collections.ArrayList = New System.Collections.ArrayList()
  33.  
  34.     Friend Function Add(ByRef formex As FormEx, ByVal key As String) As Integer
  35.         _keys.Add(key)
  36.         Return _formsex.Add(formex)
  37.     End Function
  38.  
  39.     Friend Sub Remove(ByRef formex As FormEx)
  40.         _keys.RemoveAt(_formsex.IndexOf(formex))
  41.         _formsex.Remove(formex)
  42.     End Sub
  43.  
  44.     Public ReadOnly Property Count() As Integer
  45.         Get
  46.             Return _formsex.Count()
  47.         End Get
  48.     End Property
  49.  
  50.     Public Function Contains(ByRef formex As FormEx) As Boolean
  51.         Return _formsex.Contains(formex)
  52.     End Function
  53.     Public Property Item(ByVal index As Integer) As FormEx
  54.         Get
  55.             Return CType(_formsex(index), FormEx)
  56.         End Get
  57.         Set(ByVal Value As FormEx)
  58.             _formsex(index) = Value
  59.         End Set
  60.     End Property
  61.     Public Property Item(ByVal key As String) As FormEx
  62.         Get
  63.             Return CType(_formsex(_keys.IndexOf(key)), FormEx)
  64.         End Get
  65.         Set(ByVal Value As FormEx)
  66.             _formsex(_keys.IndexOf(key)) = Value
  67.         End Set
  68.     End Property
  69. End Class