|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Single event handler for menuwould 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 wrote:
Show quoteHide quote > I have a menu, a rather big one. It contains about 150 items. Normally this Yes. With OpenForm defined as above (without a Handles clause)> 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? ' "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 Hi Larry,
Thanks, that did the trick. I appreciate it. Martin Show quoteHide quote "Larry Lard" <larryl***@hotmail.com> wrote in message news:1141913751.942359.130920@e56g2000cwe.googlegroups.com... > > Martin wrote: >> 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? > > 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 > "Martin" <x@y.com> schrieb: IIRC 'MenuItem' has an overloaded constructor which accepts the '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? 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/> Thanks for your help.
Martin Show quoteHide quote "Martin" <x@y.com> wrote in message news:%233QGSx3QGHA.5036@TK2MSFTNGP12.phx.gbl... >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 >
Garbage collection, Unmanaged code and SafeArrays
Defining data types for fields, when you a create a file Print pdf from Internet Explorer using VB .NET need ideas on multi threaded db update close Form1 & open Form2 Problem sending Report as EMail - wrong attach. name "untitled.txt" "Specified cast is not valid" converting from object A to object B Best Way to Import Fixed Width Files convert string array to long array XML Help wanted |
|||||||||||||||||||||||