Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove focus if clicked anywhere else

I have a textbox, and I want it so if the user clicks anywhere on the form that is not the textbox itself, such textbox will lose focus. Any ideas?

like image 782
Voldemort Avatar asked Jan 20 '23 01:01

Voldemort


2 Answers

Set the ActiveControl property of the form to nullto achieve what you want.

Note that this is contrary to what all other programs does, so it'll be a disconnect between the user expectations and the actual user experience. I would advice against it.

like image 173
Lasse V. Karlsen Avatar answered Jan 31 '23 10:01

Lasse V. Karlsen


Something needs to get the focus. That something is what you should click. That better be another control on the form, the form itself doesn't want the focus. It has no use for it. Or click, say, the Start button.

like image 20
Hans Passant Avatar answered Jan 31 '23 10:01

Hans Passant