Groups | Blog | Home
all groups > vb.net > march 2006 >

vb.net : Single event handler for menu



Larry Lard
3/9/2006 6:15:51 AM

[quoted text, click to view]

Yes. With OpenForm defined as above (without a Handles clause)

' "for each menu item" code omitted
' as this depends on how you build / define your menus

AddHandler theMenuItem.Click, AddressOf OpenForm

' if you build menu dynamically, do this just after creation
' for convenience

--
Larry Lard
Replies to group please
Chris Dunaway
3/9/2006 6:17:06 AM
Yes, check out the AddHandler statement.
Herfried K. Wagner [MVP]
3/9/2006 3:39:38 PM
"Martin" <x@y.com> schrieb:
[quoted text, click to view]

IIRC 'MenuItem' has an overloaded constructor which accepts the 'Click'
event handler. However, I fear that this constructor cannot be used from
within the Windows Forms designer.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Martin
3/9/2006 9:21:01 PM
I have a menu, a rather big one. It contains about 150 items. Normally this
would mean that I'd have about 150 event handlers:


Private Sub Menu1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Menu1.Click

However, I would like to get the associated form name from a different
source and then create a single event handler:

Private Sub OpenForm (ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles AllMenus.Click

In VB2005 I can assign multiple events to a single handler by specifying
them in the 'Handles' part, but for 150 items I think this is a bit much. Is
there another way to specify a handler to menu items? Like looping through
the menus and assign a specific handler?

Tia,
Martin

Martin
3/10/2006 8:58:17 PM
Hi Larry,

Thanks, that did the trick. I appreciate it.

Martin

[quoted text, click to view]

Martin
3/10/2006 8:58:58 PM
Thanks for your help.

Martin

[quoted text, click to view]

AddThis Social Bookmark Button