Reputation: 720
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 :
On another control that can get focus ( for example a textbox... ).
On another control that can't get focus ( for example a panel...)
On the form.
Is there any general method to detect this scenario : A control has the focus, the user click outside.
Thank you !
Upvotes: 0
Views: 1376
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