I want to detect if a window form is open and if it is then I would like to bring it in front rather than opening it again.
I know I need a form collection for this but I want to know if there is a built in form collection that holds all the forms in VB.NET or I need to implement my own.
Thank you.
You could try:
'Pass the form object (you could also use string as the
'parameter and replace the if condition to: "If form.Name.Equals(targetForm) Then")
Public Sub BringToFront(ByVal targetForm As Form)
Dim form As Form
For Each form In Application.OpenForms()
If form Is targetForm Then
form.BringToFront()
Exit For
End If
Next
End Sub
Call this sub if you need to bring a specific form on front (only if it is already loaded) like this:
BringToFront(targetformobject)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With