Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 3

Displaying the Pop-Up Menu

When using pop-up menus with forms or controls, you first define the menu, test for the right mouse button, and then display the desired menu.

The following source code puts together these tasks by using the PopupMenu method of the form at the same time that the mouse button has been pressed.

Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Form1.PopupMenu mnuPopup1
End If
End Sub

In this code sample, a simple If statement provides the check to see whether the right mouse button has been selected. If the Button argument equals the vbRightButton constant, the form PopupMenu method is called and passed the name of the top-level menu object to be displayed. Remember that the top-level item will not be shown, only sub-level items will be.

Any menu can be passed to the PopupMenu method. In the preceding code, a special menu named mnuPopup1 was created and its visible property was set to False. This hides the top-level menu from the application menu bar but allows the menu to be called. The PopupMenu method will display sub-level menu items regardless of the top-level menu item's visible property.

The PopupMenu method can display only one menu at a time. A second call to the PopupMenu will be ignored.


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved