Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an event handler that is fired when mouse is clicked outside textbox in c# Windows Form application?

i'm working on c# windows form application. I'd like to know if there is an event handler for textbox control that is fired whend mouse is clicked outside the textbox.I tried "Leave" and "LostFocus" event Handlers but these are fired only if the mouse is clicked on a clickable control like textbox , button or listbox but if the mouse is clicked on Form or tab or any container the handler is not fired.(To make the question more clear > i want it like the action of hiding AutoCompleteListBox of textbox when mouse is clicked outside the textbox). I hope you understand and i hope there is a direct way to this issue. Thanks

** Ok it seems that the question is not sufficient clear. I'm making a control like the AutoCompleteTextBox but it list a the items in a different way of the AutoCompleteBox.When the user writes in the textbox this control appear. Sometimes the user doesn't want to choose any of the items so he wants to hide the control by anyway. I want the user to be able to hide this control not just by choosing one of the items or clearing the textbox but also by cliking on any part of the form whatever the type of the control was."Lost Focus" and "Leave" handlers don't fire the action when the user click on form or TabControl or panel.Hope you understand.

like image 763
EgyEast Avatar asked Mar 05 '11 05:03

EgyEast


1 Answers

May I suggest a different approach? You want a smooth, hidden "AutoComplete", right? Imagine that the user has entered some partial information and wants to leave the textbox. Now, suppose the user doesn't use a mouse, but just tabs out of the textbox into another. Shouldn't that make the textbox autocomplete?

Tying the behaviour to a click outside the textbox means that, for some reason, you expect the user not to click on another control, but on the form (or immediate container to the textbox), which just isn't standard behaviour. Why would users click on nothing?

Your best approach is with the Leave and LostFocus events. Tie both to the same autocomplete function.

like image 176
MPelletier Avatar answered Nov 15 '22 12:11

MPelletier