Groups | Blog | Home
all groups > vb.net controls > february 2007 >

vb.net controls : Control arrays created at runtime


olds350racer
2/13/2007 7:15:40 AM
I am a newbie but have come across a question I hope someone can help
with.
Given the following code for a UserControl:

' Declares in the class
Private intCount as Interger
Private myLabel() as Label
' Code in the Load event of my UserControl
Dim xCount as Integer
intCount = 10
redim myLabel(intCount)
For xCount = 0 to 10
myLabel(xCount) = New Label
Me.Controls.Add(myLabel(xCount))
Next

How would I respond to an event (ie-Click) of one of my myLabel
controls? Given that the control does not exist during the design
phase, there is no event to respond to. I know this sounds like a
newbie question, but I would appreciate if anyone could point me in
the right direction.
Lou
2/14/2007 3:46:31 PM
When you create the new button add an event handler for it. Use the same
handler for all buttons

'Add the button event handler

AddHandler btn.Click, AddressOf Me.btnMacro_Click

[quoted text, click to view]

AddThis Social Bookmark Button