Form Event problem

LaLue

New member
Joined
Dec 19, 2018
Messages
3
Location
Switzerland
Programming Experience
10+
I am working with an older vb dot net version.
The program consists of a single form (no MDI application). If the user sets the cursor into another program (e.g. Word), and then back to the vb form, then at that moment I need an event to do something. I tried out several events but none of these does what it should do. Would be grateful for any help.

LaLue
 
I am working with an older vb dot net version.
The program consists of a single form (no MDI application). If the user sets the cursor into another program (e.g. Word), and then back to the vb form, then at that moment I need an event to do something. I tried out several events but none of these does what it should do. Would be grateful for any help.

LaLue
If you look in the list of events for a Form you'll notice there's a GotFocus and a LostFocus that I think you're looking for.
 
Typically, the GotFocus and LostFocus events are only used when updating UICues or when writing custom controls. Instead the Enter and Leave events should be used for all controls except the Form class, which uses the Activated and Deactivate events.
From notes of Control.GotFocus Event (System.Windows.Forms) | Microsoft Docs

Thread moved to Windows Forms forum, always prefer a specific forum over a general one.
 
WM_ACTIVATEAPP message - Windows applications | Microsoft Docs can tell you if another app is activated.
Form.WndProc(Message) Method (System.Windows.Forms) | Microsoft Docs is used to receive this message.

Example:
Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles Me.Activated
    If anotherAppActivated Then
        'another app has been active
        anotherAppActivated = False
    End If
End Sub

Private anotherAppActivated As Boolean
Private Const WM_ACTIVATEAPP = &H1C

Protected Overrides Sub WndProc(ByRef m As Message)
    MyBase.WndProc(m)
    Select Case m.Msg
        Case WM_ACTIVATEAPP
            If Not CBool(m.WParam) Then anotherAppActivated = True
    End Select
End Sub
 
Back
Top