Public Class Form1
Private Function OrderCheckBox(ByVal panelName As String) As String
Dim i As Integer = 0
Dim szText As String = String.Empty
Dim test As Panel = Me.Panel1
Dim control2 As Control
For Each control2 In test.Controls
Dim chebox As CheckBox = CType(control2, CheckBox)
If chebox.Checked = True Then
i = i + 1 //选中后加序号
szText += i.ToString() + chebox.Text.Trim() + ";"
End If
Next
Return szText
End Function
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
TextBox1.Text = OrderCheckBox("Panel1")
End Sub
End Class
本文介绍了一个使用VBA编写的函数,该函数能够遍历面板上的所有复选框,对被选中的复选框进行编号,并将编号和复选框文本返回为字符串。此外,还提供了一个文本框的键盘事件处理程序,用于调用此函数并显示结果。
1349

被折叠的 条评论
为什么被折叠?



