How to capture the lost focus on the text box?

I have texbox tbx1, when I cursor blinks in the text box, when I click on some other control, I want to display a message. But the problem is that I have to use the tbx1 text field event to capture the focus change.

+4
source share
3 answers

You can use event Leave

private void txtbox_Leave(object sender, EventArgs e)
{
        //your Code
} 

You can also use

private void txtbox_LostFocus(object sender, EventArgs e)
{
   //your Code
} 

Leave()the event first executes the keyboard event, and then the mouse event, where as the LostFocus()event the mouse event is first executed, and then the keyboard event is executed.

(TAB, SHIFT + TAB ..),

1. Enter
2. GotFocus
3. Leave
4. Validating
5. Validated
6. LostFocus 

, :

1. Enter
2. GotFocus
3. LostFocus
4. Leave
5. Validating
6. Validated 
+8

LostFocus :

private void txtbox_LostFocus(object sender, EventArgs e)
{
    //your Code
} 
+3

you can use jquery ...

<input id="txtName" type="text" />

<script type="text/javascript">
    $("#txtName").blur(function () {
        alert("I am not in textbox.");
    });
</script>
-1
source

Source: https://habr.com/ru/post/1524648/


All Articles