Context Menu: specifying the sub to handle the menu selection

T

tmaster

When I am typing the argument(s) of the Add method of MenuItems, one of the
options (#2 of 5) provides for 'OnClick as System.EventHandler' (as the
second arguement), which I hope is to provide a reference to the 'Handler'
sub:

mnuTopics.MenuItems.Add("DoSomething", DoSomething_Handler)

What is the corresponding sub syntax? The following is not the correct
syntax.

Private Sub mnuTopics_DoSomething_Handler(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles mnuTopics.DoSomething_Handler

Thanks
 
M

Mike Bulava

Try this

MnuTopics.MenuItems.Add("DoSomething", AddressOf DoSomthing_Handler)
 
I

IbrahimMalluf

Hello

In assuming that you intend to dynamically add menu items based upon some
need during runtime your handler sub only needs to look like the code below.
You would be using the same handler for all of the added menu items. Within
that handler you could branch off to different procedures based upon the
value of the sender object. If the menu additions are part of a 'Plug-In'
scheme you could use reflection to direct execution flow to the proper
procedures.

Private Sub MenuClickhandler(ByVal sender As Object, _
ByVal e AsSystem.EventArgs)



End Sub




--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx
 
H

Herfried K. Wagner [MVP]

* "tmaster said:
When I am typing the argument(s) of the Add method of MenuItems, one of the
options (#2 of 5) provides for 'OnClick as System.EventHandler' (as the
second arguement), which I hope is to provide a reference to the 'Handler'
sub:

mnuTopics.MenuItems.Add("DoSomething", DoSomething_Handler)

\\\
Me.Menu.MenuItems.Add("&Help", AddressOf MenuItem2_Click)
///
 
M

manasvin

Try

mnuTopics.MenuItems.Add("DoSomething", New EventHandler(AddressOf
mnuTopics_DoSomething_Handler))

The Sub seems fine
remove the "handles" clause

Manasvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top