How to know the current status of the form?

2

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!

    
asked by anonymous 24.03.2015 / 16:14

2 answers

2

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
    
24.03.2015 / 16:52
1

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 .

    
24.03.2015 / 16:42