Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FormCollection in VB.NET

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.

like image 483
fireBand Avatar asked Feb 20 '26 16:02

fireBand


1 Answers

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)
like image 131
Jojo Sardez Avatar answered Feb 23 '26 09:02

Jojo Sardez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!