It's pretty easy to do. Here is a piece of code that creates an array of buttons each with a click event handler:
Dim buttons(4) As Button
For i As Integer = 0 To 3
buttons(i) = New Button
buttons(i).Top = i * 50
buttons(i).Height = 40
buttons(i).Width = 100
buttons(i).Text = ';Button';
AddHandler buttons(i).Click, AddressOf Button1_Click
Me.Controls.Add(buttons(i))
Next
The AddHandler command will cause each button to call the event function Button1_Click when it is clicked.
I want to handle events in Vb.net when controls are added with arrays?
You can't handle events of objects in arrays.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment