BUG: Control Loses Focus When Another Window is Activated

Last reviewed: October 16, 1996
Article ID: Q150227
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

SYMPTOMS

If the TabStop property of a control is set to False and the focus is set to that control at run-time, and if another window in the same application or a different application is activated, when the focus is set back to the original window, the control no longer has the focus.

STATUS

Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this issue and will post new information here in the Microsoft Knowledge Base as it becomes available.

WORKAROUND

Temporarily set the TabStop property to True in the GotFocus event, and set it back to False in the LostFocus event. If the user changes over to another application or window while the control has the focus, the focus returns to the original control when the window is activated. For example, if, at the beginning of the program, the Text1 control was not going to have the focus, the following code could be inserted in the GotFocus and LostFocus events of the Text control:

   Private Sub Text1_GotFocus()
      Text1.TabStop = True
      End Sub
      Private Sub Text1_LostFocus()
      Text1.TabStop = False
   End Sub

MORE INFORMATION

Steps to Reproduce Problem

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Place two Text boxes on Form1.

  3. Set the TabStop property of the Text1 text box to False.

  4. Run the project by pressing F5. Note that the Text2 text box has the focus when the form appears. Click on the Text1 text box, and then click on any other window in the Desktop, or press ALT+TAB to switch to another application.

  5. Return the focus to Form1 by clicking on its Title bar or by pressing ALT+TAB. Note that the Text2 text box has the focus.

To work around this problem, place the code in the Workaround Section above into the code for Form1.


Additional reference words: 4.00 vb4win vb4all buglist4.00
KBCategory: kbprg kbbuglist
KBSubcategory: PrgOther



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 16, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.