I have a Form which covers the entire screen. I have a textbox
on it which is normally hidden but appears when a user clicks, drags mouse and then leaves. After that user can enter any value in the text box. Once entered, ideally user should be able to click outside of textbox and then the normal service should resume.
By normal service I mean that form should start getting all the events. What I have done so far is that on TextBox's KeyDown event; when Escape key is pressed, I have set the focus to the main form like this:
this.Focus(); //where this is mainform.
But this doesn't seem to work since Textbox
still keeps receiving all the keys. I have a KeyDown
event handler both for Form
and Textbox
and I have checked that all the KeyDown
events pass on to the TextBox. I have a TextBox
Leave event Handler as well which never gets called.
This TextBox
is the only control on the form and the main form is used for drawing shapes (if that matters).
So, how can I make this TextBox
lose focus when user clicks outside of it.