16,554
社区成员
发帖
与我相关
我的任务
分享
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim checkbox_list As New List(Of CheckBox)
For Each c As Control In Me.Controls
If Not TypeOf c Is CheckBox Then Continue For
checkbox_list.Add(CType(c, CheckBox))
Next
checkbox_list.Sort(AddressOf CheckBoxComparison)
For i As Integer = 0 To checkbox_list.Count - 1
MessageBox.Show("ComboBox" + (i + 1).ToString() + " : " + IIf(checkbox_list(i).Checked, "选中", "没选中"))
Next
End Sub
Public Function CheckBoxComparison(ByVal x As CheckBox, ByVal y As CheckBox) As Integer
Return String.Compare(x.Name, y.Name, True)
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim all_true As Boolean = True
For Each c As Control In Me.Controls
If Not TypeOf c Is CheckBox Then Continue For
Dim check As CheckBox = CType(c, CheckBox)
If Not check.Checked Then
all_true = False
Exit For
End If
Next
MessageBox.Show(IIf(all_true, "都打钩了", "有的没打钩"))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim combobox_array As CheckBox() = (From c In Controls.Cast(Of Control)() Order By c.Name Where TypeOf c Is CheckBox Select TryCast(c, CheckBox)).ToArray()
For i As Integer = 0 To combobox_array.Length - 1
If combobox_array(i).Checked Then
'你的代码
End If
Next
End Sub
For Each a As Control In Me.Controls
If CType(a,CheckBox) <> Nothing Then'这样做比 is 快
Dim check As CheckBox = CType(a, CheckBox)
MsgBox(check.Text & ":" & IIf(check.Checked, "选中", "未选中"))
End If
Next
For Each a As Control In Me.Controls
If a.GetType Is GetType(CheckBox) Then
Dim check As CheckBox = CType(a, CheckBox)
MsgBox(check.Text & ":" & IIf(check.Checked, "选中", "未选中"))
End If
Next
For Each a As Control In Me.Controls
If a.GetType Is GetType(CheckBox) Then
Dim check As CheckBox = CType(a, CheckBox)
MsgBox(check.Text & ":" & IIf(check.Checked, "选中", "未选中"))
End If
Next