PRB: GotFocus Occurs Before Click Event When Option Selected (138528)



The information in this article applies to:

  • Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
  • Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
  • Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
  • Microsoft Visual Basic Standard Edition for Windows 3.0
  • Microsoft Visual Basic Professional Edition for Windows 3.0

This article was previously published under Q138528

SYMPTOMS

The GotFocus event occurs before a Click event for an option button when an access key instead of the mouse is used to select the option. This is different from the behavior of command buttons and check boxes where the Click event occurs before the GotFocus event when an access key is used to select the control.

STATUS

Microsoft is researching this behavior and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The order of the GotFocus and Click events depends on how the control was selected. A mouse click generates a GotFocus event followed by a Click event for Command buttons, Check boxes, and Option buttons.

The order of the GotFocus and Click events reverse for command buttons and check boxes when an access key is used. The following table lists the events in the order in which they occur for each type of control.
Type of Control          MouseClick               Access Key
Command Button           GotFocus, Click          Click, GotFocus
Check Box                GotFocus, Click          Click, GotFocus
Option Button            GotFocus, Click          GotFocus, Click
				

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. On Form1, place a command button, two option buttons, and a check box. Set the following properties for each control:
       Control             Name           Caption
       --------------------------------------------
       Command Button      Command1       &Command1
    
       Option Buttons      Option1        &Option1
                           Option2        Option2
    
       Check Box           Check1         C&heck1
    					
  3. In the Click event for each control, place the following line of code:
       Debug.Print Me.ActiveControl.Caption " Click"
  4. In the GotFocus event for each control, place the following line of code:
       Debug.Print Me.ActiveControl.Caption " GotFocus"
  5. Run the example by pressing the F5 key. To bring the Debug window to the foreground, on the View menu, click Debug Window in Visual Basic 4.0, or on the Window menu, click Debug in Visual Basic 3.0.
  6. Click each control, and note the order in which the events take place. Then select each control by using the access keys:

    ALT+C for the command button
    ALT+O for the first option button
    ALT+H for the check box control.


Modification Type:MajorLast Reviewed:1/11/2001
Keywords:kbDSupport kbprb KB138528 kbAudDeveloper