I'm a beginner in the field, I could not find my question elsewhere.
Is there a code that shows the state of the form?
For example: if it is in focus, is it minimized or maximized?
Thanks in advance!
I'm a beginner in the field, I could not find my question elsewhere.
Is there a code that shows the state of the form?
For example: if it is in focus, is it minimized or maximized?
Thanks in advance!
To get or change the state of a form, use Form.WindowState
.
MessageBox.Show(WindowState.ToString()) ' Normal, Maximizado ou Minimizado '
Or if you need to perform an action in a particular state, you can do:
If WindowState = FormWindowState.Maximized Then
' O formulário está maximizado '
ElseIf WindowState = FormWindowState.Minimized Then
' O formulário está minimizado '
ElseIf WindowState = FormWindowState.Normal Then
' O formulário está normal '
Else
' Estado desconhecido '
End If
To find out if a control is in focus, use Control.Focused
.
If Me.Focused Then
' Este formulário está em foco '
Else
' Não está em foco '
End If
You would have to put two events in your form to note its state in a variable. For example:
Private formAtivo As Boolean
Private Sub meuForm_Activated(sender As Object, e As EventArgs) Handles MyBase.Activated
formAtivo = True
End Sub
Private Sub meuForm_Deactivate(sender As Object, e As EventArgs) Handles MyBase.Deactivate
formAtivo = False
End Sub
To know if the form is active, just read formAtivo
. I got the answer from here .
formAtivo
does not have to be Private
.