Dynamic buttons

  • Thread starter Thread starter TyBreaker
  • Start date Start date
T

TyBreaker

I'm creating buttons on the fly as my program runs and I'm storing them
all in an array for future referencing. How do I assign a click event
handler to a button I've created dynamically?
--
______ ___ __
/_ __/_ __/ _ )_______ ___ _/ /_____ ____
/ / / // / _ / __/ -_) _ `/ '_/ -_) __/
/_/ \_, /____/_/ \__/\_,_/_/\_\\__/_/
/___/

There are 10 types of people in this world; those who understand the
binary numbering system and those who don't.

There's no place like 127.0.0.1.

ASCII a silly question, get a silly ANSI.
 
Hi,

Below is an example :
----------------------------------------------
Private Sub AddButtons()
Dim NewBtn As New Button()
Me.Controls.Add(NewBtn)
idx = Me.Controls.IndexOf(NewBtn)
NewBtn.Location = New System.Drawing.Point(24 * idx, 24 * idx)
NewBtn.Text = "Button " & idx.ToString()
' Note the following statement :
AddHandler NewBtn.Click, AddressOf MyButtonClickHandler
End Sub

Private Sub MyButtonClickHandler(ByVal sender As System.Object, ByVal e
As System.EventArgs)
' Handle the Click events of all the Buttons here...
End Sub
----------------------------------------------

HTH,

Regards,

Cerebrus.
 
Back
Top