This example shows you how to display a popup menu...
First, you need to add a number of controls:
|
Type
|
Name
|
Caption
|
| Label |
lblPopup |
Right click for popup menu |
| Label |
lblDefaultPopup |
Right click for popup menu with default item |
| Label |
lblShowPopupAtX |
Right click here to display popup at X |
| Label |
lblX |
X |
| Menu |
mnuTest |
Test Menu |
| Menu |
mnuTestItem1 |
Test Item 1 |
| Menu |
mnuTestItem2 |
Test Item 2 |
Make sure that mnuTestItem 1 and 2 are sub menus of mnuTest. Now, add the code
below, run your project, and try right clicking on each of the labels.
Private Sub lblDefaultPopup_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
If Button = vbRightButton Then '// is right button?
PopupMenu mnuTest, , , , mnuTestItem1
'// display popup menu
End If
End Sub
Private Sub lblPopUp_MouseDown(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Button = vbRightButton Then '// is right button?
PopupMenu mnuTest '// show popup
End If
End Sub
Private Sub cmdHidePopup_Click()
mnuTest.Visible = False '// hide the popup menu from the main
menu bar
End Sub
Private Sub lblShowPopupAtX_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If Button = vbRightButton Then
'// get the coordinates of the X
label (x and y)
PopupMenu mnuTest, , lblX.Left,
lblX.Top '// display menu
End If
End Sub