Dynamic buttons

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.
 
C

Cerebrus

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

System Icons? 2
Prompting for an IP address 4
Disposing - when? 1
Form Layout 3
Floating Menu Bar 6
Appbar and Tooltips 1
VB.NET Appbar example? 1
VB2005: Controls not appearing on form 3

Top