Supposed you have an event handler like:
Private Sub Buttons_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
MessageBox.Show(sender.ToString())
End Sub
Then you'd want to change the setup code to something like:
Dim bt(10, 10) As Button
Dim x, y As Integer
For y = 0 To 9
For x = 0 To 9
bt(x, y) = New Button
bt(x, y).Text = String.Format("B{0},{1}", x, y)
bt(x, y).Size = New Size(35, 25)
bt(x, y).Location = New Point(40 * x, 30 * y)
AddHandler bt(x, y).Click, AddressOf Buttons_Click
Me.Controls.Add(bt(x, y))
Next
Next
(Note the AddHandler that points to the event handler for Click).
> Thank you Ed, that's exactly what I needed!
> Now, how to hook up the onClick event to every button?
[quoted text clipped - 54 lines]
>> > I would be grateful for any help!
>> > Hrvoje
Hrvoje Vrbanc - 14 Jan 2005 17:05 GMT
Ed, thank you very much!
You helped me a lot.
Hrvoje
> Supposed you have an event handler like:
> Private Sub Buttons_Click(ByVal sender As System.Object, ByVal e As
[quoted text clipped - 67 lines]
> > one
> >> > question: what is the best way to dynamically add e.g. 100 buttons in
> >> > 10
> > x
[quoted text clipped - 18 lines]
> >> > I would be grateful for any help!
> >> > Hrvoje