See Also Example
Applies To
Form (not MDI form), check box
Description
Occurs when an object receives the focus Note that a form receives the focus only when all visible controls are disabled.
Syntax
Sub Form_GotFocus ( )
Sub ctlname_GotFocus (Index As Integer)
Remarks
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 Enabled and Visible properties are set to True. To customize Visual Basic's keyboard interface for moving the focus, set the Tab order or specify access keys for controls on a form.
Help:
ActiveControl Property
ActiveForm Property
LostFocus Event
SetFocus Method
TabIndex Property
TabStop Property
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
End Sub
Sub OptionGroup_GotFocus (Index As Integer)
Select Case Index
Case 0
Label1.Caption = "Option 1 has the focus."
Case 1
Label1.Caption = "Option 2 has the focus."
End Select
End Sub
Sub OptionGroup_LostFocus (Index As Integer)
Label1.Caption = ""
End Sub