I need to dunamically create buttons on a windows forms depending on the data
that is requested.
How can I create an event handler on the fly for this buttons?

Signature
Arne Garvander
Certified Geek
Professional Data Dude
Michael C - 23 Jan 2008 05:43 GMT
>I need to dunamically create buttons on a windows forms depending on the
>data
> that is requested.
> How can I create an event handler on the fly for this buttons?
This is it in C#, to convert to VB you add the word addressof inside the
brackets but I'm not sure what you do with the +=. Probably
MyButton.Click.AddSomething...
MyButton.Click += new EventHandler(FunctionToCall);
Michael
Jack Jackson - 23 Jan 2008 07:08 GMT
>I need to dunamically create buttons on a windows forms depending on the data
>that is requested.
>How can I create an event handler on the fly for this buttons?
dim btn as System.Windows.Forms.Button
...
btn = New System.Window.Forms.Button
Me.Controls.Add(btn)
Addhandler btn.Click, AddressOf ButtonClickHandler
...
Private Sub ButtonClickHandler(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
End Sub
Arne Garvander - 23 Jan 2008 14:16 GMT
Jack,
Thanks.
I need 1 to many buttons. Is there a way I can make all the buttons use the
same event handler?

Signature
Arne Garvander
Certified Geek
Professional Data Dude
> >I need to dunamically create buttons on a windows forms depending on the data
> >that is requested.
[quoted text clipped - 10 lines]
>
> End Sub
Herfried K. Wagner [MVP] - 23 Jan 2008 14:21 GMT
"Arne Garvander" <ArneGarvander@discussions.microsoft.com> schrieb:
> I need 1 to many buttons. Is there a way I can make all the buttons use
> the
> same event handler?
Yes, via 'AddHandler'. Simply specify the same handling routine for the
buttons' events.
Inside the event handler the 'sender' parameter will contain a reference to
the control the event belongs to.

Signature
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>