In a separate class, Checkbox
are created and are displayed on the form.
Here is class:
class checkboxcreate
{
Checkbox [] check;
Private Form Cont;
Public CheckBoxCreate (Form Control)
{
this.cont = Cont;
}
Public Void CreateCheck ()
{
DirectoryInfo Dir = New DirectoryInfo (@ "12");
FileInfo [] inf = dir.getfiles ("* .txt");
Check = new checkbox [inf.length];
for (int i = 0; i & lt; inf.length; i ++)
{
Check [i] = New Checkbox ();
Check [i] .visible = True;
Check [i] .Parent = CONT;
Check [i] .location = New Point (200, 5 + I * 50);
Check [i] .name = i.tostring ();
Check [i] .text = "Chekbox number" + i;
Check [i] .Checked = True;
Check [i] .width = 120;
Check [i] .Height = 40;
Check [i] .CheckedChanged + = New Eventhandler (check_change);
CONT.CONTROLS.ADD (CHECK [I]);
}
}
Public Void Check_Change (Object Sender, Eventargs E)
{
}
}
Everything works well and is displayed correctly.
On the form there is a button when clicking it should call the check_change
Class to uncheck all flags from the created Checkbox
How best to do where to dig?
It’s just an outline to connect everything and write a program.
Answer 1, Authority 100%
Removing the check from Chekbox is the reason, calling an event (and all its handlers, in your case – check_change
) is a consequence. The opposite is incorrect. Those. Manual call method Check_change
Does not affect the state of checkbox.
Change the status of the checkbox can be set the value of the Checked property. Set it for all checkboxes on the form you can approximately like this:
Private Void Button1_Click (Object Sender, Eventargs E)
{
Foreach (Var Checkbox in this.controls.oftype & lt; Checkbox & gt; ())
{
checkbox.checked = True;
}
}
In your case, you are also tracking created by checkboxes, so it’s enough to remember the link to the used checkboxcreate in the form field, and in the button handler, use them for the bore of Chekboxers:
Field class field:
hackboxcreate checkboxcreate;
Checkbox creation code:
this.checkboxcreate = new checkboxcreate (this);
this.checkboxcreate.createCheck ();
Click on the button:
Private Void Button1_Click (Object Sender, Eventargs E)
{
this.checkboxcreate.checkall ();
}
where
class checkboxcreate
{
...
Public Void Checkall ()
{
Foreach (Var Checkbox in this.check)
{
checkbox.checked = True;
}
}
}