vb detect mouse click

carloselfaite
carloselfaite used Ask the Experts™
on
Hi, I neew to detect when user click outside my form.
I am using visualstudio 2015 vb.net
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
Maybe the Form's Deactivate event (https://msdn.microsoft.com/en-us/library/system.windows.forms.form.deactivate(v=vs.110).aspx) is what you are looking for?

What are you trying to achieve?
Top Expert 2016

Commented:
It can be done but it means writing a routine that delves deep into the operating system.  Windows Forms are not designed to detect clicks outside of their space. It might be easier to check for focus changes
Senior Software Engineer
Commented:
You can add a timer and use GetAsyncKeyState() windows API function inside the timer tick function.

<DllImport("user32.dll")> _
Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Short
End Function

Open in new window


Timer Tick:
If GetAsyncKeyState(Keys.LButton) <> 0 Then
    ' TODO: Add code here to handle left mouse click...
End If

Open in new window

Author

Commented:
perfect

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial