Occurs when the control loses focus.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
When you change the focus by using the keyboard (TAB, SHIFT+TAB, 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:
When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:
The GotFocus and events are low-level focus events that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the GotFocus and events are only used when updating UICues or when writing custom controls. Instead the Enter and Leave events should be used for all controls except the Form class, which uses the Activated and Deactivate events. For more information about the GotFocus and events, see the WM_KILLFOCUS and WM_KILLFOCUS topics.
Do not attempt to set focus from within the Enter, GotFocus, Leave, , Validating, or Validated event handlers. Doing so can cause your application or the operating system to stop responding. For more information, see the WM_KILLFOCUS topic.
For more information about handling events, see Handling and Raising Events.
The following code example demonstrates validating the text for TextBox1. It also demonstrates handling the FileDialog.InitialDirectory property to the text in TextBox1. The code example used the ErrorProvider.GetError method to check for an error before opening the file dialog box. To run this example, paste the following code into a form containing a TextBox named TextBox1, an OpenFileDialog named OpenFileDialog1, a Button named Button1, and an ErrorProvider named ErrorProvider1. Ensure all events are associated with their event handlers.event by setting the
Available since 1.1