Knowledge Base |

# BUG: Incorrect Popup Menu Events Fired with Invisible Menus

Article ID: 116058

Article Last Modified on 12/9/2003

APPLIES TO

- Microsoft Visual Basic 2.0 Standard Edition
- Microsoft Visual Basic 3.0 Professional Edition
- Microsoft Visual Basic 2.0 Professional Edition
- Microsoft Visual Basic 3.0 Professional Edition

This article was previously published under Q116058

## SYMPTOMS

When the following conditions are met, Visual Basic may incorrectly fire a menu's Click event for the first visible menu item under the first menu on the form:

- You use the PopupMenu method to display a menu that has its Visible property set to False.
- The PopupMenu is not the first (leftmost) menu on the form, and the first menu on the form also has its Visible property set to False.

Under these conditions, the Click event for the first visible menu item on the first menu will be fired immediately after the PopupMenu method is called, so the desired PopupMenu will not be displayed.

## WORKAROUND

To work around this problem, either:

- Make the first menu on the form visible. -or-
- Place all popup menus on a separate form. Then you can leave all the menus on your popup menus visible, but make the form that contains them invisible. To make the form invisible, set the form's visible property to false. You can invoke popup menus from other forms by referring to the form name and then the menu name, as in this example:

         PopupMenu Form2.Menu2

## STATUS

Microsoft has confirmed this to be a bug in Visual Basic version 3.0. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

## MORE INFORMATION

### Steps to Reproduce Problem

1. Start a new project in Visual Basic. Form1 is created by default.
2. Add the following menu items:

           Caption           Name       Visible
           ------------------------------------
           Menu1             mMenu1     False
           ....Menu1Item1    mMenu11    True
           Menu2             mMenu2     False
           ....Menu2Item1    mMenu21    True

3. Add the following code for menu items:

          Sub mMenu11_Click ()
             Msgbox "Item1"
          End Sub

          Sub mMenu21_Click ()
             MsgBox "Item2"
          End Sub

4. Add the following code to the Form_MouseDown event:

          ' Place following two lines of code on one, single line:
          Sub Form_MouseDown (button As Integer, Shift As Integer, X As Single,
             Y As  Single)

             If button = 2 Then
                PopupMenu mMenu2
             Else
                PopupMenu mMenu1
             End If

          End Sub

5. Run the application.
6. Click the client area of Form1. Then click the Item1 popup menu item. The correct message box will appear.
7. With Right mouse button, click the client area of Form1. The Item1 message box will appear, indicating the click event was generated for the first menu item under top-level menu 1.

Additional query words: buglist3.00 3.00 buglist3.00 hidden

Keywords: kbbug KB116058