Find form instances in vb 2008

Dim f as new frmNameHere  
f.show()

How to find all instances frmNameHerecreated using the above code?

+5
source share
1 answer

For instance:

For i As Int32 = 1 To 10
   Dim frm As New frmNameHere()
   frm.Show()
Next
Dim openForms = Application.OpenForms.OfType(Of frmNameHere)()
While openForms.Any()
   openForms.First.Close()
End While

It also works without linq, but then you need to go through all OpenForms:

Dim forms As FormCollection = Application.OpenForms
For Each form As Form In forms
   If TypeOf form Is frmNameHere Then
      'do something with your frmNameHere-Form'
   End If
Next
+9
source

All Articles