tags:

views:

177

answers:

3

Which event should I use for this?

A: 

Control.LostFocus.

Wil P
It's not listed under TextBox property editor. Do you know why?
Joan Venge
Just not shown in the property editor. You can add it from code behind. If Control.Leave is there as Johannes suggested you could use that as well.
Wil P
It is not shown in the properties window because the event is marked with [BrowsableAttribute(false)] http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx
Martin Robins
A: 

'Control.LostFocus'

Martin Robins
It's not listed under TextBox property editor. Do you know why?
Joan Venge
+3  A: 

Control.Leave or Control.LostFocus:

When you change the focus by using the keyboard (, +, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl.ActiveControl property to the current form, focus events occur 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 the CausesValidation property is set to false, the Validating and Validated events are suppressed.

Joey
This is strange, when I lose the focus with mouse, I don't get Validated event to fire for some reason.
Joan Venge
Some controls may not fire it; also CausesValidation may be set to `false`. And `Validated` is not strictly a focus event, as in, you shouldn't use it as a "focus lost" event. It's for validation purposes.
Joey
Thanks Johannes.
Joan Venge