I have a texbox tbx1, when I have the cursor blinking on the textbox, when I click the mouse on some other control I want to display a message, But the issue is I have to use an event of the textbox tbx1 to capture that focus change.
The LostFocus event occurs after the Exit event. If you move the focus to a control on a form, and that control doesn't have the focus on that form, the Exit and LostFocus events for the control that does have the focus on the form occur before the Enter and GotFocus events for the control you moved to.
VB6 controls fire the Validate event first and then the LostFocus event; if the Validate sets Cancel=True, then the LostFocus event is never fired. The sequence is the same regardless of how the end user moves the input focus away from the control.
Net. A very useful event you can use for text boxes is the Leave event. It allows you to validate a text box when a user tries to leave it. You can check, for example, if the text box is blank.
You can use Leave
event
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()
event first executes keyboard event and then executes mouse event where as LostFocus()
event first executes mouse event and then executes keyboard event.
Basically When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), the events occurred in the following order
1. Enter
2. GotFocus
3. Leave
4. Validating
5. Validated
6. LostFocus
When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:
1. Enter
2. GotFocus
3. LostFocus
4. Leave
5. Validating
6. Validated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With