On May 31, 11:39 am, "Lou" <lou.gar...@com cast.netwrote:
I want to dynamically create an unknown amount of buttons into a panel.
I want each button to respond to the same click event.
In VB6 I would just create an array of buttons.
I do know how to have multiple buttons respond to the same click event in
.NET but
not if the number of buttons are not know until runtime are created
dynamically .
Example
App starts and a reg setting says create 25 buttons.
Thanks
-Lou
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim numberOfButtons As Integer =
CInt(Microsoft. Win32.Registry. GetValue("HKEY_ CURRENT_USER\Bu ttonDemo
\", "NumberOfButton s", 25))
For i As Integer = 0 To numberOfButtons - 1
Dim b As New Button()
AddHandler b.Click, AddressOf buttons_Click
b.Text = String.Format(" Button{0}", i.ToString())
b.Top = 30 * i
Me.Panel1.Contr ols.Add(b)
Next
End Sub
Private Sub buttons_Click(B yVal sender As Object, ByVal e As
EventArgs)
Dim theButton As Button = DirectCast(send er, Button)
MsgBox(String.F ormat("{0} said Hello World!", theButton.Text) )
End Sub
End Class
Thanks,
Seth Rowe