Results 1 to 3 of 3

Thread: Sub items in a dynamic menustrip

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    23

    Sub items in a dynamic menustrip

    hello i have managed to add menu strip items and add a Click Handler to it fine

    But now i am going to remove the click handler, and want to add sub items in the menu instead the current code i have so far..

    Code:
     Dim IEToolStripMenuItem As New ToolStripMenuItem("Web", Nothing, Nothing, "Web")
            DynOS.MenuStrip1.Items.Add(IEToolStripMenuItem)
            AddHandler IEToolStripMenuItem.Click, AddressOf Switcher
    I just want it to list more sub items in the "Web" menu its creating. i'm sure adding the Click Handler would be pretty easy once i figure this out.

    Appreciate any help

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Sub items in a dynamic menustrip

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim IEToolStripMenuItem As New ToolStripMenuItem("Web", Nothing, Nothing, "Web")
    5.         Dim subitem1 As New ToolStripMenuItem("subitem1", Nothing, Nothing, "subitem1")
    6.         IEToolStripMenuItem.DropDownItems.Add(subitem1)
    7.         Dim subitem2 As New ToolStripMenuItem("subitem2", Nothing, AddressOf clickHandler, "subitem2")
    8.         Dim subitem3 As New ToolStripMenuItem("subitem3", Nothing, AddressOf clickHandler, "subitem3")
    9.         subitem1.DropDownItems.Add(subitem2)
    10.         subitem1.DropDownItems.Add(subitem3)
    11.         MenuStrip1.Items.Add(IEToolStripMenuItem)
    12.     End Sub
    13.  
    14.     Private Sub clickHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
    15.         MsgBox(DirectCast(sender, ToolStripMenuItem).Name)
    16.     End Sub
    17.  
    18. End Class

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    23

    Re: Sub items in a dynamic menustrip

    that's perfect i appreciate the help big time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width