Creating Menu & Submenus Programmatically



I want to create menu & sub menu programmatically
on a form. Can anyome Help?

Cheers! !! !!!

Comments

  • [italic]
    : I want to create menu & sub menu programmatically
    : on a form. Can anyome Help?
    :
    : Cheers! !! !!!
    [/italic]

    [code]
    Public Sub AddMenuAndItems()
    Dim mnuFileMenu as New MainMenu()
    Dim myMenuItemFile as New MenuItem("&File")
    Dim myMenuItemNew as New MenuItem("&New")
    Dim myMenuItemFolder as New MenuItem("&Options")

    'add menu item
    mnuFileMenu.MenuItems.Add(myMenuItemFile)
    myMenuItemFile.MenuItems.Add(myMenuItemNew)

    'another method
    mnuFileMenu.MenuItems.Add("Save &As")


    'add submenu item
    myMenuItemNew.MenuItems.Add(myMenuItemFolder)


    Me.Menu = mnuFileMenu

    End Sub

    [/code]

    another example from MSDN
    [code]
    Public Sub CreateMyMenu()
    ' Create a main menu object.
    Dim mainMenu1 As New MainMenu()

    ' Create empty menu item objects.
    Dim menuItem1 As New MenuItem()
    Dim menuItem2 As New MenuItem()

    ' Set the caption of the menu items.
    menuItem1.Text = "&File"
    menuItem2.Text = "&Edit"

    ' Add the menu items to the main menu.
    mainMenu1.MenuItems.Add(menuItem1)
    mainMenu1.MenuItems.Add(menuItem2)

    ' Add functionality to the menu items using the Click event.
    AddHandler menuItem1.Click, AddressOf Me.menuItem1_Click
    AddHandler menuItem2.Click, AddressOf Me.menuItem2_Click

    ' Assign mainMenu1 to the form.
    Me.Menu = mainMenu1
    End Sub 'CreateMyMenu
    [/code]

    MSDN article....
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskaddingmenusitemstomenu.asp

  • : [italic]
    : : I want to create menu & sub menu programmatically
    : : on a form. Can anyome Help?
    : :
    : : Cheers! !! !!!
    : [/italic]
    :
    : [code]
    : Public Sub AddMenuAndItems()
    : Dim mnuFileMenu as New MainMenu()
    : Dim myMenuItemFile as New MenuItem("&File")
    : Dim myMenuItemNew as New MenuItem("&New")
    : Dim myMenuItemFolder as New MenuItem("&Options")
    :
    : 'add menu item
    : mnuFileMenu.MenuItems.Add(myMenuItemFile)
    : myMenuItemFile.MenuItems.Add(myMenuItemNew)
    :
    : 'another method
    : mnuFileMenu.MenuItems.Add("Save &As")
    :
    :
    : 'add submenu item
    : myMenuItemNew.MenuItems.Add(myMenuItemFolder)
    :
    :
    : Me.Menu = mnuFileMenu
    :
    : End Sub
    :
    : [/code]
    :
    : another example from MSDN
    : [code]
    : Public Sub CreateMyMenu()
    : ' Create a main menu object.
    : Dim mainMenu1 As New MainMenu()
    :
    : ' Create empty menu item objects.
    : Dim menuItem1 As New MenuItem()
    : Dim menuItem2 As New MenuItem()
    :
    : ' Set the caption of the menu items.
    : menuItem1.Text = "&File"
    : menuItem2.Text = "&Edit"
    :
    : ' Add the menu items to the main menu.
    : mainMenu1.MenuItems.Add(menuItem1)
    : mainMenu1.MenuItems.Add(menuItem2)
    :
    : ' Add functionality to the menu items using the Click event.
    : AddHandler menuItem1.Click, AddressOf Me.menuItem1_Click
    : AddHandler menuItem2.Click, AddressOf Me.menuItem2_Click
    :
    : ' Assign mainMenu1 to the form.
    : Me.Menu = mainMenu1
    : End Sub 'CreateMyMenu
    : [/code]
    :
    : MSDN article....
    : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskaddingmenusitemstomenu.asp
    :
    :
    [blue]Correct me if I am wrong but I think[/blue] [b]this will work only with VB.NET[/b].
  • [italic]
    : Correct me if I am wrong but I think this will work only with VB.NET.
    [/italic]

    Whoops... looks like Kel is right. There doesn't appear to be a way in pre VB.NET that I can find, but you could create all the instances you would need in the menu, then programmatically make them visible or not.
  • : [italic]
    : : I want to create menu & sub menu programmatically
    : : on a form. Can anyome Help?
    : :
    : : Cheers! !! !!!
    : [/italic]
    :
    : [code]
    : Public Sub AddMenuAndItems()
    : Dim mnuFileMenu as New MainMenu()
    : Dim myMenuItemFile as New MenuItem("&File")
    : Dim myMenuItemNew as New MenuItem("&New")
    : Dim myMenuItemFolder as New MenuItem("&Options")
    :
    : 'add menu item
    : mnuFileMenu.MenuItems.Add(myMenuItemFile)
    : myMenuItemFile.MenuItems.Add(myMenuItemNew)
    :
    : 'another method
    : mnuFileMenu.MenuItems.Add("Save &As")
    :
    :
    : 'add submenu item
    : myMenuItemNew.MenuItems.Add(myMenuItemFolder)
    :
    :
    : Me.Menu = mnuFileMenu
    :
    : End Sub
    :
    : [/code]
    :
    : another example from MSDN
    : [code]
    : Public Sub CreateMyMenu()
    : ' Create a main menu object.
    : Dim mainMenu1 As New MainMenu()
    :
    : ' Create empty menu item objects.
    : Dim menuItem1 As New MenuItem()
    : Dim menuItem2 As New MenuItem()
    :
    : ' Set the caption of the menu items.
    : menuItem1.Text = "&File"
    : menuItem2.Text = "&Edit"
    :
    : ' Add the menu items to the main menu.
    : mainMenu1.MenuItems.Add(menuItem1)
    : mainMenu1.MenuItems.Add(menuItem2)
    :
    : ' Add functionality to the menu items using the Click event.
    : AddHandler menuItem1.Click, AddressOf Me.menuItem1_Click
    : AddHandler menuItem2.Click, AddressOf Me.menuItem2_Click
    :
    : ' Assign mainMenu1 to the form.
    : Me.Menu = mainMenu1
    : End Sub 'CreateMyMenu
    : [/code]
    :
    : MSDN article....
    : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskaddingmenusitemstomenu.asp
    :
    :

    There should be a way out in VB6. What do u guys sugguest.

  • : I want to create menu & sub menu programmatically
    :
    What is the reason to do that?
    :
  • Good Day!

    I have created a database consisting all menu and submenu items, and i want to select these menus and submenus based on the userid. it is a form of secruity features such that not all user can have access to some menus & sbmenus

    Best Regards


    : : I want to create menu & sub menu programmatically
    : :
    : What is the reason to do that?
    : :
    :



  • : Good Day!
    :
    : I have created a database consisting all menu and submenu items, and i want to select these menus and submenus based on the userid. it is a form of secruity features such that not all user can have access to some menus & sbmenus
    :
    : Best Regards
    :
    :
    : : : I want to create menu & sub menu programmatically
    : : :
    : : What is the reason to do that?
    : : :
    : :
    :
    :
    :
    :
    I think the best way to do that is ceate reqular menu and change property enabled to true or false depending on userid. It's just my ipinion.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories