alex
alex

Reputation: 720

VB.NET : How to detect a mouse click outside a focused control

I'm using vb.net. I have a control ( for example a button , or a textbox ... or something else ) that has the focus.

I want to detect when the user click outside this control.

The click may be :

Is there any general method to detect this scenario : A control has the focus, the user click outside.

Thank you !

Upvotes: 0

Views: 1376

Answers (1)

jmoreno
jmoreno

Reputation: 13561

Not built in, but I believe it can be done -- use AddHandler control.click on all of the controls except for the one you want to to know when the click was for something else.

Sub RegisterControls(cntrl as Control)
   For Each c as Control in cntrl
      AddHandler c.click, AddressOf Whatever
      If c.Controls.Count >0 Then RegisterControls(c)
   Next
End Sub

Upvotes: 1

Related Questions