Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleCreate menus flexibly at run time
Keywordsmenu
CategoriesControls
 
Use Load to create the new menus. Examine the caption of selected items to see which routines to invoke.
 
Private Sub Form_Load()
    ' Create the menu items.
    CreateMenuItem "Command &1"
    CreateMenuItem "Command &2"
    CreateMenuItem "Command &3"
End Sub

' Create a new menu item in the Commands menu.
Private Sub CreateMenuItem(ByVal menu_caption As String)
Static menu_num As Integer

    ' Create the menu entry.
    If mnuCommands.Enabled Then
        ' Load a new entry.
        menu_num = menu_num + 1
        Load mnuCommandsSub(menu_num)
    Else
        ' This is the first menu item. Use entry 0.
        mnuCommands.Enabled = True
        menu_num = 0
    End If

    mnuCommandsSub(menu_num).Caption = menu_caption
End Sub

Private Sub mnuCommandsSub_Click(Index As Integer)
    Select Case mnuCommandsSub(Index).Caption
        Case "Command &1"
            MsgBox "Execute command 1"
        Case "Command &2"
            MsgBox "Execute command 2"
        Case "Command &3"
            MsgBox "Execute command 3"
    End Select
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated