Is there an event handler that fires when the mouse is clicked outside the text box in a C # Windows Form application?

I am working on a C # form application. I would like to know if there is an event handler for the text box control that fires when the mouse is called outside the text box. I tried to process the Leave and Lost Focus event handlers, but they only start if the mouse is clicked on an interactive text box, button or list, but if you click on the form or tab or in any container, the handler will not start. (To make the question more understandable), I want it to be like the action of hiding the AutoCompleteListBox of a text field when you click outside the text field). I hope you understand, and I hope that there is a direct path to this problem. Thanks

** Well, it seems that the question is not clear enough. I am making a control like AutoCompleteTextBox, but it lists the elements differently from AutoCompleteBox. When the user writes to the text box, this control appears. Sometimes the user does not want to select an element, so he wants to hide the control. I want the user to be able to hide this control not only by selecting one of the elements or clearing the text field, but also by clicking on any part of the form, regardless of the type of control. The Lost Focus and Leave handlers do not trigger an action when the user clicks on a form or TabControl or panel. I hope you understand.

+5
source share
2 answers

An autocomplete list is displayed until the text field becomes the focus. Clicking outside the text box is really one way to make the text box lose focus. But this requires you to click on what you want to get focus. The form does not, it is useless for this, why it does not work.

Getting a window to view mouse events occurring outside the window requires mouse capture. Winforms supports this Control.Capture property. Set to true and all mouse messages will be sent to the control, even if the mouse is no longer closer to the window. You should use the MouseDown event and check the mouse position in the client window area to find that the mouse was clicked outside the window.

, . , . , , , . , . , , , , . , , . , , . . , . , , Winforms.

, , . , , . , . , .

, . , . , IMessageFilter.

+3

? , "", ? , . , , . ?

, - , , ( ), , ?

Leave LostFocus. .

+4

All Articles