By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Dynamic buttons

P: n/a
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.
Mar 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"TyBreaker" <ty*********@SPAMhotmail.com> schrieb
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?

http://msdn.microsoft.com/library/en...OnRemoveOn.asp

Armin
Mar 25 '06 #2

P: n/a
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.

Mar 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.