Reputation: 15861
I thought that Leave was supposed to fire when a control loses focus, and MouseLeave was supposed to fire when the mouse is no longer in the control.
I have a TextBox, and if I click in it, then take the mouse out, the Leave event fires. I'm using Leave to validate the entry in the box, like when people hit tab to go to the next control.
Does this mean that a TextBox can't have focus unless the mouse remains in it?
Upvotes: 1
Views: 1081
Reputation: 57658
You should not be using Leave
or LostFocus
for validation purposes, instead use TextBox.Validating
which is designed specifically for validation scenarios.
This way, if you want to have a Cancel
button for example, you can just set its CausesValidation
property to false and editor controls Validating
events will not fire.
Upvotes: 3
Reputation: 73243
You must have some other code setting focus, because Leave does not fire when the mouse moves out of the control.
Upvotes: 3
Reputation: 3
It doesn't matter if the mouse is in it. Property Focus refers to another type of event, when a component is ready to have its value changed, It doesn't matter if you use the keyboard or the mouse. Why don't you validate TextBox value when the Textbox looses Focus?
Upvotes: 0