Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 31,066 times

Contents

Related Categories

Menus - Checked menu items

Checked menu items

Sometimes you may want the user to be able to select options on the menu. You may have noticed other applications using Ticks or circles next to an item to show that this option is chosen. You can do this is VB too. All you have to do is change the checked property of the menu item. Note that when a checked menu item is clicked, VB will not automatically uncheck the item. The following example will check and un-check mnuEditWordWrap and change the text in a label.

For this example, create a menu called mnuEdit, with a menu item called mnuEditWordWrap. Also add a label control to the form.

Sub mnuEditWordWrap_Click()
    If mnuEditWordWrap.Checked = True
        ' We are checked - uncheck the menu item                 mnuEditWordWrap.Checked = False
        ' Set the label text
        Label1.Caption = "No Word Wrap"
    Else
        ' We are not checked - check the menu item
        mnuEditWordWrap.Checked = True
        ' Set the label text
        Label1.Caption = "Word Wrap"
    End If
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • help with the code

    Posted by minor on 28 Apr 2003

    In this tutorial i dosent tell you the code for the menu. and im also very new to vb so if someone could tell me what i need to do for the code that would be great.

  • VFlags variable not defined?

    Posted by planethax on 17 Nov 2002

    I have made a menu with1 1 Item (about) set it to enable - unchecked visable
    made a click event(msg box)

    then in my form mouse up event I put
    [code]
    Private Sub Form_MouseUp(Button As Integer, ...

  • Posted by James Crowley on 20 May 2002

    sorry 'bout that... there was an old style link lurking in there... I have corrected the link on

    http://www.developerfusion.com/show/15/10/, which now points to

    http://www.developerfusion.com/sh...

  • example

    Posted by Rollershade on 20 May 2002

    i click view an example and no example???
    i really want to change the look of my menu,change color or nything? ny ideas?