Hi
Here is a stand alone example that may help. This is for dynamically adding Buttons but the principle is the same for most/any controls. It can easily be changed to add CheckBoxes if needed - just adjust the Properties being added. See line 26, where the same event handler is allocated to each Button.
' Blank Form1, copy/replace all
' default code with this code
Option Strict On
Option Explicit On
Public Class Form1
Dim pan As New Panel
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Size = New Size(500, 300)
With pan
.Location = New Point(5, 5)
.Size = New Size(ClientSize.Width - 20, 220)
.BackColor = Color.Beige
.BorderStyle = BorderStyle.FixedSingle
End With
Controls.Add(pan)
SetButtons(18)
End Sub
Sub SetButtons(num As Integer)
Dim x As Integer = 2
Dim y As Integer = 5
Dim yStep As Integer = 30
Dim cs As Integer = pan.Height
For i As Integer = 1 To num
Dim mybutton As New Button With {.Text = "Button" & i.ToString(), .Name = "Button" & i.ToString(), .Location = New Point(x, y), .BackColor = Color.LightGray, .AutoSize = True}
pan.Controls.Add(mybutton)
AddHandler mybutton.Click, AddressOf ButtonClick
y += yStep
If y + yStep >= cs Then
x += 100
y = 5
End If
Next
End Sub
Public Sub ButtonClick(sender As Object, e As EventArgs)
Dim butt As Button = DirectCast(sender, Button)
MessageBox.Show("Selected Button = " & butt.Name)
End Sub
End Class