See Also Example
Form (not MDI form), check box, combo box , command button , directory list box , drive list box , file list box , grid , horizontal scroll bar , list box , OLE control , option button , picture box , text box , vertical scroll bar .
Occurs when an object receives the focus Note that a form receives the focus only when all visible controls are disabled., either by user action such as tabbing to or clicking the object, or by changing the focus in code using the SetFocus method.
Sub Form_GotFocus ( )
Sub ctlname_GotFocus (Index As Integer)
The argument Index uniquely identifies a control if it is in a control array. Typically, you use a GotFocus procedure to specify the actions that occur when a control or form first receives the focus. For example, by attaching a GotFocus procedure to each control on a form, you can guide the user by displaying brief instructions or status bar messages. You can also provide visual cues by enabling, disabling, or showing other controls that depend on the control that has the focus.
Note An object can receive the focus only if its Enabled3XD4FN and Visible properties are set to True. To customize Visual Basic's keyboard interface for moving the focus, set the Tab order1JL4HCO or specify access keys for controls on a form.
GotFocus Event Example
The example displays a status bar message when a button in an option group gets the focus. To try this example, paste the code into the Declarations section of a form that contains two option buttons and a label. Set the Name property for both option buttons to OptionGroup. Then press F5 and click the option buttons.
Sub Form_Load ()
Label1.AutoSize = True
Sub OptionGroup_GotFocus (Index As Integer)
Select Case Index
Label1.Caption = "Option 1 has the focus."
Label1.Caption = "Option 2 has the focus."
Sub OptionGroup_LostFocus (Index As Integer)
Label1.Caption = ""