|
-
Aug 4th, 2012, 07:05 PM
#1
Thread Starter
Addicted Member
[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..
-
Aug 4th, 2012, 07:25 PM
#2
New Member
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
-
Aug 4th, 2012, 07:46 PM
#3
Thread Starter
Addicted Member
Re: How do I check if a form has focus or is active?
i tried it. didn't work though.
Any other suggestions?
-
Aug 4th, 2012, 08:14 PM
#4
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 =
Last edited by .paul.; Aug 4th, 2012 at 08:18 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 4th, 2012, 08:22 PM
#5
Thread Starter
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|