VB6 Tutorial 60: Popup menu
Most commercial software products have popup menus (also known as context menus) as they can make the application more user-friendly and powerful.
When you right click on windows desktop, a popup menu appears. Visual Basic 6.0 provides a Popup menu method that you can use in your program to show the popup menu on the form's surface.
To use the Popup menu method, you first need to create a menu. For example, create a menu with the name "View". See the example given below.
The PopupMenu method
Syntax
PopupMenu Menu, [Flags], [X], [Y], [DefaultMenu]
Note: Arguments in [ ] brackets are optional.
Now write the following code in the form's MouseDown event to invoke the popup menu.
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then PopupMenu mnuView 'PopupMenu is a method End If End Sub
If you need only the popup menu but not the menu bar, set the Visible property of the menu control to False in design time.
About this post
Posted: 2018-06-02
By: vb6boy
Viewed: 3,618 times
Categories
Attachments
popupmenu.zip
Posted: 6/9/2018 6:29:25 AM
Size: 1,104 bytes
Loading Comments ...
Comments
You must be logged in to make a comment.
AnonymousCoward posted this comment on 2020-04-23:
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, _ X As Single, Y As Single) If Button And vbRightButton Then ' User right-clicked the list box. PopupMenu mnuListPopup End If End Sub The x and y arguments, if specified, make the menu appear in a particular position on the form, rather than at mouse coordinates. The last optional argument is the name of the menu that's the default item for the pop-up menu. This item will be displayed in boldface. This argument has only a visual effect; If you want to offer a default menu item, you must write code in the MouseDown event procedure to trap double-clicks with the right button.