forms collection in vb.net 
Author Message
 forms collection in vb.net

Hi all

I rewrite a vb 6 application in vb.net, my problem it is that my code in vb6
is as follows

   For Each frmForm In Forms
      If frmForm.Name <> sNomFeuille And frmForm.Name <> "frmFond" Then
         Unload frmForm
      End If
   Next

and vb.net do not support the collection forms.  you know a solution ?

thanks



Sat, 13 Nov 2004 21:24:04 GMT  
 forms collection in vb.net
Create your own forms collection, I've found some code posted here by
someone but don't know who.

HTH
Corrado



Sat, 13 Nov 2004 21:43:34 GMT  
 forms collection in vb.net


Quote:
> Hi all

> I rewrite a vb 6 application in vb.net, my problem it is that my code in vb6
> is as follows

>    For Each frmForm In Forms
>       If frmForm.Name <> sNomFeuille And frmForm.Name <> "frmFond" Then
>          Unload frmForm
>       End If
>    Next

> and vb.net do not support the collection forms.  you know a solution ?

http://groups.google.com/groups?selm=MPG.16f965e2780675d5989b4a%
40msnews.microsoft.com

--
Patrick Steele
Microsoft .NET MVP



Sat, 13 Nov 2004 23:35:10 GMT  
 forms collection in vb.net
The forms collection cannot be upgraded automatically, so if the previous
code is upgraded, the collection is marked with an upgrade issue:

'UPGRADE_ISSUE: Forms collection was not upgraded.
For Each f In Forms

The only way to achieve the same effect in Visual Basic .NET is to
implement your own forms collection. Luckily, this is easier than it
sounds. First create a new Visual Basic .NET Windows application. Add a new
module, and in the module put the following code (you can find this code on
the companion CD in the file FormCollectionClass.vb):

Module FormsCollection
Public Forms As New FormsCollectionClass()
End Module
Class FormsCollectionClass : Implements IEnumerable
   Private c As New Collection()
   Sub Add(ByVal f As Form)
      c.Add(f)
   End Sub
   Sub Remove(ByVal f As Form)
      Dim itemCount As Integer
      For itemCount = 1 To c.Count
         If f Is c.Item(itemCount) Then
            c.Remove(itemCount)
            Exit For
         End If
      Next
   End Sub
   ReadOnly Property Item(ByVal index) As Form
      Get
         Return c.Item(index)
      End Get
   End Property
   Overridable Function GetEnumerator() As _
      IEnumerator Implements IEnumerable.GetEnumerator
      Return c.GetEnumerator
   End Function
End Class

This is the collection that will maintain your collection of forms. You
need to make sure that each form is added to the collection when it is
created and removed from the collection when it is disposed of. In the New
event for Form1, insert the following line:

Forms.Add(Me)
In the Disposed event, insert this line:

Forms.Remove(Me)
That's all you need to do to implement your forms collection. If your
application has many forms, you'll have to put the New and Dispose code in
every one.

Let's see how to use this collection in code. The following Visual Basic
NET example does exactly what the first Visual Basic 6 example in this
chapter did: loop through the forms collection, determine whether a form
called Form1 is open, and unload it if it is open.

Dim f As Form
For Each f In Forms
   If f.Name = "Form1" Then
      f.Close()
   End If
Next
You can use this forms collection to unload forms, loop through the
collection of open forms, or simply check whether a particular form is open.

Best regards,
Perry Deng
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.



Sun, 14 Nov 2004 18:52:02 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How can I perform forms collection in VB.NET

2. Forms collection in VB.Net

3. No more Forms Collection in VB.Net?

4. forms collection in vb.net

5. Forms Collection gone from VB.net

6. Forms collection for .NET?

7. VB.NET with ASP.NET web forms

8. Deploying vb.net windows form application on a pc without the .net framework

9. Passing Form Fields to VB.NET Custom Business Object in an ASP.NET Code Behind Page

10. Serialization of Collection in VB.NET

11. Custom Collections in VB.NET

 

 
Powered by phpBB® Forum Software