..


Sponsored Links

Right from the menu in Visual Basic 6

Article written by Luca Ruggiero
Page 1 of 2

A form of Visual Basic 6 does not natively have the ability to activate a context menu when you press the right mouse button, very useful option for the developer and the user of the software under certain circumstances.

VB6 has the MouseUp event that can be associated with a form element through the classical event-driven syntax of the language.

Let's take an introductory example.

We create a new form by opening our copy of Visual Basic 6, we double-click anywhere on the form so that the editor of VB6 us back to Form_Load.

Posizioniamoci with the cursor on the event (on the text: Form_Load) and open up to the event handler select MouseUp:

At this point, the editor will see the new routine Form_MouseUp with all its parameters:
Also manually delete the Form_Load procedure.

Of course it is possible to associate this event to any element of a form, simply by double-clicking, and the code, performing the same sequence of operations.

Inside the new routine will write a check like this:






 Private Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)



    



 Then If Button = vbRightButton



        



 MsgBox ""



    



 End If







 End Sub



Button is the first parameter of the routine, internal type, while the constant vbRightButton returns a Boolean value of zero (0) is false if the event or to one (1) if the event is true.

Trying to right click on the running form will return an empty message box.

The generation of a menu from the right calls for the integration of this simple example with the normal creation of a menu in VB6 , as explained in the article just linked.

Based on the article just linked explanations, we create a menu with the following features:

  • Main Menu (Caption: "My Menu" - Name: "MyMenu")
    • Submenu 1 (Caption: "Item 1" - Name: "V1")
    • Submenu 2 (Caption: "Voice 2" - Name: "V2")
During construction the menu will then have the following characteristics:
Warning: such as shown in the image, remember to uncheck the "Visible" to the main menu, since, by default, the menu is not visible because it is activated by clicking the right mouse button.

In the same category ...
E-Learning
MS Access (Course) MS Access (Course)
Learn how to create and manage databases easily and quickly. Starting from 29 €.
Visual Basic 6 (Course) Visual Basic 6 (Course)
Make desktop applications with VB6. Starting from 39 €.
Sponsored Links