Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find instances of a form in vb 2008

Dim f as new frmNameHere  
f.show()

How do I find all instances of frmNameHere created using the above code?

like image 484
Prinzovdarkness Avatar asked Jan 18 '11 22:01

Prinzovdarkness


1 Answers

For example:

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

Works also without linq, but then you have to iterate 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
like image 122
Tim Schmelter Avatar answered Oct 18 '22 06:10

Tim Schmelter