BUG: Menu Accelerators Still Work When Form is Disabled
ID: Q192252
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
SYMPTOMS
You have a Visual Basic form whose Enabled property has been set to False.
All user input is disabled except for the menu accelerator keys. The user
can still invoke code on a disabled form through the accelerator keys (such
as pressing ALT+F X on the keyboard to invoke the File|Exit command).
RESOLUTION
When disabling a Form to prevent all user input, top-level menu items must
be disabled as well. For example:
Private Sub DisableForm()
Form1.Enabled = False
mnuFile.Enabled = False
End Sub
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
MORE INFORMATION
Steps to Reproduce Behavior
- Create a new Standard EXE project in Visual Basic. Form1 is created
by default.
- Add a CommandButton to Form1.
- Open the Menu Editor (CTRL+E) and add the following menu items:
Caption: &File
Name: mnuFile
The next item should be indented:
Caption: E&xit
Name: mnuExit
- Add the following code to the Code Window for Form1:
Private Sub Form_Load()
Command1.Caption = "Disable Form"
End Sub
Private Sub Command1_Click()
Me.Enabled = False
End Sub
Private Sub mnuExit_Click()
MsgBox "Exit Called!!"
Me.Enabled = True
End Sub
- Compile the program and run it as an EXE.
- Click the Disable Form button and then click the Exit menu. As expected,
all user input is disabled. This means you cannot select menu items
using the mouse. However, you can use the accelerator key combination
ALT+X to invoke the menu command. The code in the mnuExit_Click event
resets the Enabled property to True.
NOTE: Depending on the version of Windows and Visual Basic you are
using, the problem may not appear in the IDE. However, the problem does
occur in the compiled executable.
Additional query words:
kbDSupport kbDSD kbVBp kbVBp600bug kbVBp500bug kbMenu kbIDE
Keywords : kbGrpVB
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbbug