Which event should I use for this?
When showing a form that contains a TextBox, it's common courtesy to focus the TextBox so that the user can begin typing immediately. To focus a TextBox when a Windows Form first loads, simply set the TabIndex for the TextBox to zero (or the lowest TabIndex for any Control on the Form).
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.
Step 1: Create a windows form. Step 2: Drag the TextBox control from the ToolBox and Drop it on the windows form. You can place TextBox anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the TextBox control to set the Text property of the TextBox.
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:
- Enter
- GotFocus
- Leave
- Validating
- Validated
- LostFocus
When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:
- Enter
- GotFocus
- LostFocus
- Leave
- Validating
- Validated
If the CausesValidation property is set to false, the Validating and Validated events are suppressed.
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