为了配合 AVD 所说的,在您分配动态 TabPages 的循环中创建您的 CheckBox。您将需要预先创建组合框或在另一个 for 循环中动态创建它们。然后,我将使用他们的 Tag 属性为每个 CheckBox 分配一个唯一 ID,并使用它来区分在 Common CheckedChanged 事件中更改了哪个。像这样的东西。
Dim index As Integer = 0
For j = 1 To 10 '#10 tab pages considered
Dim startLocation As Point = New Point(10, 10)
TabControl1.TabPages.Add(New TabPage)
TabControl1.TabPages(j).Text = "Folder" & j + 1
For x = 0 To 7
Dim chkbx As New CheckBox
TabControl1.TabPages(j).Controls.Add(chkbx)
chkbx.Tag = index
chkbx.Text = "FolderName"
chkbx.Location = startLocation
chkbx.Size = New Size(220, 17)
AddHandler chkbx.CheckedChanged, AddressOf CheckBox_CheckedChanged
startLocation.Y = startLocation.Y + 16
index += 1
Next
Next
CheckChanged 事件
Private Sub CheckBox_CheckedChanged(sender As System.Object, e As System.EventArgs)
Dim cb As CheckBox = CType(sender, CheckBox)
Select Case CInt(cb.Tag)
Case 0
Case 1
Case 2
Case 3
Case .... 'Up to how ever many index's that you have
Case Else
End Select
End Sub