I have a window with 3 user controls on it. My main goal is to determine if the window or any of its controls has focus and also when that changes.
I am trying to do this with the Activated and Deactivated events of the window.
I have a problem with them firing reliably or at all. But first does any one have a better idea.
I want to receive an event when the window or any control receives focus and also an event when the user clicks on something other than my app.
Here is my failing / unreliable attempt.
Private dbBar_ActivatedEvent As System.EventHandler
Private dbBar_DeActivatedEvent As System.EventHandler
dbBar_ActivatedEvent = New System.EventHandler(AddressOf DBBar_Activated)
dbBar_DeActivatedEvent = New System.EventHandler(AddressOf DBBar_Deactivated)
Then adding or removing looks like this
AddHandler Me.Activated, dbBar_ActivatedEvent
AddHandler Me.Deactivated, dbBar_DeActivatedEvent
RemoveHandler Me.Activated, dbBar_ActivatedEvent
RemoveHandler Me.Deactivated, dbBar_DeActivatedEvent
The two events
Private Sub DBBar_Deactivated(ByVal sender As Object, ByVal e As System.EventArgs)
Private Sub DBBar_Activated(ByVal sender As Object, ByVal e As System.EventArgs)
The strange things I am seeing are things like. They fire while debugging with Visual studio but if running the .exe they do not.
One of the controls has a textbox and if you click this text box some times the activated event fires and sometimes not.