A few days ago, I saw a post in the .NET technology forum, I seem to remember how to implement the CheckBoxList control in Winform in Winform, I have a simple implementation of such controls.
First, you have to build a control project, if you say:
Then, you add a class: checkboxcollection, it is a collection class for Checkbox
The specific code is as follows
Checkboxcollection.cs
Using system.collections; using system.windows.forms;
namespace CheckListControl {///
Public CheckBox this [int index] {get {return (checkbox) list [index];}} public checkbox add (checkbox obj) {base.list.add (obj); return obj;}
Public void remove (Checkbox Obj) {base.list.remove (obj);}}}
Then, in the checkboxlist.cs file, define global variables
Private checkboxcollection objcbc = new checkboxcollection ();
Public event system.eventhandler checkedchanged;
Write custom functions, external interface
///
this.controls.add (cb); // Add Checkbox to the control
INT x = getMaxwidth (); // Get the maximum width IF (Cb.Width> x) of the added Checkbox // If the maximum width of the Checkbox added now is greater than the maximum width already added, replace the tune x {x = Cb.Width 24;
this.size = new size (x, y 12 24); / / / / According to the added Checkbox change control size
Return Cb;}
///
///
///
// [Browsable (TRUE), Description ("Get Checkbox Collection"), Category ("Checklist")] // public checkboxcollection checklist // {// Get // {// Return Objcbc; ///} //}
Private void checkbox_checkedchanged (Object sender, Eventargs E) {CheckedChanged (Sender, New Eventargs ());} You can get CheckListControl.dll after compiling;
Add new projects for class test
In the toolbox -> Add / remove the item, add checklistControl, then drag CHECKLISTCONTROL to FORM1
Form1.cs
private void Form1_Load (object sender, System.EventArgs e) {CheckBox cb = checkBoxList1.NewCheckBox (); cb.Name = "chkFirst"; cb.Text = "First CheckBox"; cb.Size = new Size (125, 24); CB = CheckBoxList1.Newcheckbox (); cb.name = "chksecond"; cb.text = "Second Checkbox"; cb.size = new size (125, 24);
Private void checkboxlist1_checkedchanged (Object sender, system.eventargs e) {checkbox cb = (checkbox) sender; messagebox.show ("name:" cb.name "text:" cb.text);
This is the case
In fact, just a simple CheckBoxList, there are many other features, and hope users correct, add more features.