[RESOLVED] How do I check if a form has focus or is active?
I just want to blink the taskbar icon if the app has an alert occur while the user is working with another application (I already know how to blink the taskbar icon).
I have tried Me.focused
code:
Code:
Private Sub Textbox1_TextChanged(sender As Object, e As System.EventArgs) Handles Textbox1.TextChanged
'Textbox1.SelectionStart = Len(Textbox1.Text)
' Textbox1.SelectionLength = 0
If Me.Focused = False Then
My.Computer.Audio.Play(My.Resources.Alert, AudioPlayMode.WaitToComplete)
FlashWindow(Me.Handle, 1)
End If
End Sub
HELP please..
Re: How do I check if a form has focus or is active?
Well your code logicaly should work, because in my application I used something similar
Try this though, it might not response to me.focused=false
Code:
Private Sub Textbox1_TextChanged(sender As Object, e As System.EventArgs) Handles Textbox1.TextChanged
'Textbox1.SelectionStart = Len(Textbox1.Text)
' Textbox1.SelectionLength = 0
If Me.Focused = True Then
'do nothing
Else
My.Computer.Audio.Play(My.Resources.Alert, AudioPlayMode.WaitToComplete)
FlashWindow(Me.Handle, 1)
End If
End Sub
Re: How do I check if a form has focus or is active?
i tried it. :( didn't work though.
Any other suggestions?
Re: How do I check if a form has focus or is active?
try this:
vb.net Code:
Public Class Form1
Private Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As IntPtr
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If GetActiveWindow = Me.Handle Then
My.Computer.Audio.Play(My.Resources.Alert, AudioPlayMode.WaitToComplete)
FlashWindow(Me.Handle, 1)
End If
End Sub
End Class
edit: that should be <> not =
Re: How do I check if a form has focus or is active?
Since i wanted it to notify me when the txtbox is update while form is inactive i changed the = to <>
Worked great!.. Thank you .paul. :D