PRB: GotFocus Occurs Before Click Event When Option Selected

Last reviewed: October 30, 1995
Article ID: Q138528
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

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.


Additional reference words: 3.00 4.00 vb4win vb4all
KBCategory: kbprg kbprb
KBSubcategory: PrgCtrlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 30, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.