CheckBox, which is a common control in various development locales and Web pages.
Below, this article is to explain the c#winform version of the checkbox, control traversal, select all, anti-select instance code.
① Direct Reference
If a CheckBox control is present in a form, the method of direct reference is:
The control name. Property = Property Value
Example: Checkbox1.checked = true;
② Traversal Reference
There are two cases of traversing a reference, one for which the CheckBox control is not contained within any container, and the other is that the CheckBox control is contained within some containers.
A:checkbox traversal method that is not contained within any container
foreach inch this. Controls)// Use this here. Controls { if is as CheckBox; ifnull) true; // Select All }}}
A:checkbox the traversal method contained within the container (for example, contained within a groupbox)
foreach (Control mycheckbox in Groupbox1.controls) // use container name here GroupBox1 { if (MyCheckBox Span style= "color: #0000ff;" >is checkbox) {CheckBox ck = MyCheckBox
as
CheckBox;
if
CK. Checked) {ck. Checked =!ck. Checked;
//
inverse selection
Another case is that the form does not use the CheckBox control control, but instead uses CheckBoxList, and if we want to implement traversal, refer to the following code:
for (int i =0; i<checklistbox.items.count;i++) {MessageBox.Show (checklistbox.items[0) ]. ToString ()); }
C#winform version of CheckBox, Checklistbox control Traversal code