Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have a form which has a lot of ToolStripMenuItem that created by the designer and I want to assign a same event handler to them, how do I do that?

Here's my code
VB
Private Sub AddEventClick(ByVal target As ToolStripItemCollection)
    For i As Integer = 0 To target.Count
        Dim ts As ToolStripMenuItem = target(i)
        If ts.HasDropDownItems Then AddEventClick(ts.DropDownItems)
        'Here I want to assign the event handler
        'tsh.AddClickEvent(ts)
    Next
End Sub
Private Sub toolStripDrawing()
    tsh = New TSHandler
    Dim target As ToolStripItemCollection = BuatObjekToolStripMenuItem.DropDownItems
    AddEventClick(target)
End Sub


Any idea to do this? I really don't want to assign each event one by one (since it'll be too troublesome to update)
Posted

1 solution

Use AddHandler
VB
AddHandler ts.Click, AddressOf ToolStripMenuItem_Click 'place the name of your function
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 10-Jun-11 13:43pm    
Sure, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900