copying an event handler in vb.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using vb.net and basically I am trying to build a series of buttons at
runtime based on menu entries created at design time on a ContextMenuStrip

What I would like to do is make the Click event of a button created at
runtime execute the same event handler as the Click event of the
ToolStripMenuItem.

so in pseudo code
newButton.OnClick = menuItem.OnClick

I wondered is this possible via reflection to get the event handlers address
to use in an AddHandler call for the button, but I am not sure how to go
about this.


Thanks Adrian
 
See the article in Windows Forms Tips and Tricks on how to discover the
targets of an event.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Thanks bob

I get the bit about the getting the list of deleagtes but how then can the
target sub of the delegate be assigned to another control event as well.
Addhandler wants an addressof as the last parameter and AddHandler
(myButton.click, Addressof aDelegate.Method) seems not to work.

It could be I am just being a little stupid here
 
Back
Top