Visual Basic Reference

GotFocus Event Example

This example displays a status bar message when a button in an OptionButton group gets the focus. To try this example, paste the code into the Declarations section of a form that contains two OptionButton controls and a Label control. Set the Name property for both OptionButton controls to OptionGroup, and then press F5 and click the OptionButton controls.

  Private Sub Form_Load ()
   Label1.AutoSize = True
End Sub

Private 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

Private Sub OptionGroup_LostFocus (Index As Integer)
   Label1.Caption = ""
End Sub