FIX: CommandButton Receives Keystroke from Open Dialog

ID: Q181010


The information in this article applies to:
  • Microsoft Windows CE Toolkit for Visual Basic 5.0, version 1.0


SYMPTOMS

If a CommandButton has the focus and is used to open a MessageBox, InputBox, or form, when you use the ENTER key to close the MessageBox, InputBox, or form, the Click event procedure of the CommandButton executes.


CAUSE

The ENTER key strokes returned from an open dialog or other form are interpreted by a CommandButton as a Click event.


RESOLUTION

There are two workarounds for this problem.

  1. Close the open MessageBox, InputBox, or form with a mouse (or stylus) action.


  2. When a MessageBox or InputBox is called from a CommandButton, add code to set the focus to the next control in the CommandButton Click event procedure, such as:
    
    Msgbox "All Done"
          Text1.SetFocus 



STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.


MORE INFORMATION

This problem occurs when using the ENTER key to close a MessageBox, an InputBox, or another form:

  • With a MessageBox, use the ENTER key to dismiss it.


  • With the InputBox function, the user can TAB to the desired button (OK, Yes, No, etc.) and select it with the ENTER key.


  • With another form that has a CLOSE button, the user can TAB to it and select it with the ENTER key.


Steps to Reproduce Behavior

  1. Open a new Windows CE project in Visual Basic. Form1 is created by default.


  2. Add a CommandButton and TextBox to Form1; they will be named Command1 and Text1 by default.


  3. Add the following code to Form1:
    
          Private Sub Command1_Click()
             MsgBox "Command1.Click"
          End Sub
    
          Private Sub Text1_Click()
             MsgBox "Text1.Click"
          End Sub 


  4. Press the F5 key to run the project.


  5. Click on Command1. Use the ENTER key to close the MessageBox dialog and note that the Command1 Click event procedure runs again.


  6. Close the MessageBox dialog using a mouse or stylus by clicking OK. Note that the CommandButton Click event procedure does not repeat.


  7. Click on Text1. Use the ENTER key to close the MessageBox dialog and note that the TextBox Click event procedure does not repeat.



REFERENCES

Books Online for Microsoft Windows CE Toolkit for Visual Basic 5.0

Additional query words: wce vbce vbce5 vbce6

Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600fix kbWinCE kbWinCE100 kbGrpVB
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: February 24, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.