Microsoft KB Archive/149277

= BUG: SSCommand Click Fired with Double-Click in Common Dialog =

Article ID: 149277

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q149277



SYMPTOMS
Double-clicking a file name in a common dialog box that happens to be displayed immediately above an SSCommand button will cause the Click event for the SSCommand button to be fired.



WORKAROUND
This problem can be worked around in two ways. The easiest and quickest route is to replace all SSCommand buttons with regular command buttons. The regular command button does not show this behavior.

Another alternative is to set the enabled property of the SSCommand button to false immediately before showing the common dialog box. If this route is taken then a timer must be utilized to switch the enabled property of the SSCommand back to True. If Enabled is set to true immediately after the common dialog box returns (or even after a delay loop), the SSCommand will still have its click event fired. The following is a step-by-step example for this fix (this can be followed after the reproduction sample below):

 Add a single timer control to the form. Set these properties of the timer control:

Enabled: False

Interval: 1

  Add this code to the Timer1_Timer event: Private Sub Timer1_Timer SSCommand1.Enabled = True Timer1.Enabled = False End Sub   In code, add this line immediately before the common dialog is shown: SSCommand1.Enabled = False   Add this line of code immediately after the common dialog is shown: Timer1.Enabled = True 

This code will turn off the SSCommand immediately before showing the common dialog box. When the dialog box returns, the timer will be enabled, its event will fire 1 millisecond later, re-enabling the SSCommand, and then it will turn itself off.



STATUS
Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article.

<div class="moreinformation_section">

Steps to Reproduce Behavior
 Start Visual Basic 4.0. Form1 is created by default.</li> Add a single SSCommand button to the form. Size the button to be very large so that the reproduction is easier to accomplish.</li> Add an additional regular command button and a single common dialog box control.</li>  Add this code to Form1: Private Sub SSCommand1_Click MsgBox "SSCommand clicked" End Sub

Private Sub Command1_Click CommonDialog1.Filter = "(*.txt)|*.txt" CommonDialog1.ShowOpen End Sub </li> Press F5 or select Start from the Run menu to run the application. Click on the regular command button to display the Open common dialog box. Ensure that the common dialog box is positioned such that a file name is immediately over the SSCommand. Double-click the file name, and see that, after the common dialog box is dismissed, a message box is displayed indicating that the SSCommand button has been clicked.</li></ol>

Keywords: kbbug KB149277

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.