VB6 Tutorial 59: Menus

Posted On 2018-06-01 by VB6Boy
Keywords: visual,basic,vb6,visualbasic,tutorial,basic,beginner
Tags: VB6 Tutorials 
Views: 28

Looking for the more of the VB6 Tutorial? Here is the tutorial index.

Menus are one of the most important features of a software product. Every standard software must have menus. You generally see a menu on top of a software interface.

Menus are controls but different from the controls in the ToolBox and they don't work like the other controls. You can drop a menu on the form from the Menu Editor Window. Press Ctrl+E to show the Menu Editor Window or right-click on the form and click Menu Editor. The Menu Editor Window can also be shown from the Menu Editor icon of the ToolBar.

Building a menu

Building a menu is very simple, you can do it on your own. Simply fill the Caption and Name field in the Menu Editor Window and click ok to create it.

menu builder

Click the right-arrow button to create a submenu. Click Next to create the next menu item, and click ok once you're done editing the menu items.

A simple form with menu:

simple menu

Properties of the menu items

The important properties of the menu items are Name, Caption, Checked, Enabled, Shortcut and Visible. As per your programming need, set the properties either in run-time or in design time. You can create a shortcut key for a menu item. In some situations you may want to disable a menu item, you can acquire it through the Enabled property.

The menu control exposes only one event, the Click event.


Make a menu as same as the following image.

Code behind the menu

Now write the following code.

Private Sub mnuBlue_Click()
    Form1.BackColor = vbBlue 'Makes the Form blue
End Sub

Private Sub mnuGreen_Click()
    Form1.BackColor = vbGreen 'Makes the form green
End Sub

Private Sub mnuRed_Click()
    Form1.BackColor = vbRed  'Makes the form red
End Sub

Private Sub mnuWhite_Click()
    Form1.BackColor = vbWhite  'Makes the form white
End Sub

Now run the program and Click on the menu items and see what happens.

The Checked property

Design a form like the output image of the following program. Create a Help menu and drop a Label control on the form with the caption 'Help'.

Checked menu item

Now write the following code.

Private Sub mnuShowHelp_Click()
    If mnuShowHelp.Checked = True Then
        mnuShowHelp.Checked = False
        Label2.Visible = False
    ElseIf mnuShowHelp.Checked = False Then
        mnuShowHelp.Checked = True
        Label2.Visible = True
    End If
End Sub

Looking for the more of the VB6 Tutorial? Here is the tutorial index.

About the Author

has posted a total of 101 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links