Button event handler

  • Thread starter Thread starter Arne Garvander
  • Start date Start date
A

Arne Garvander

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?
 
Arne Garvander said:
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
 
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
 
Jack,
Thanks.
I need 1 to many buttons. Is there a way I can make all the buttons use the
same event handler?
 
Arne Garvander said:
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.
 
Back
Top