namespacewindowsformsapplication1{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidForm1_Load (Objectsender, EventArgs e) { foreach(Control ctlinch This. Controls)//traversing controls in a form { if(CTL. GetType (). Name = ="CheckBox")//determines whether the type of control is a checkbox{checkbox cbox= (checkbox) CTL;//casting a traversed controlCbox. Autoellipsis =true;//set text too long display ...
//cbox. CheckAlign = ContentAlignment.MiddleCenter; do not dare to write this option, otherwise run the result as
Cbox. CheckAlign =Contentalignment.bottomright;Cbox. Checked=false; } } } //Select basketball check box Private voidCheckbox1_checkedchanged (Objectsender, EventArgs e) { if(checkbox1.checked)//determine if CheckBox1 is selected { if(richTextBox1.Text = ="") richTextBox1.Text= Checkbox1.text;//assign a value to a text box ElserichTextBox1.Text+=","+Checkbox1.text; } } //Select football check box Private voidCheckbox2_checkedchanged (Objectsender, EventArgs e) { if(checkbox2.checked)//determine if CheckBox2 is selected { if(richTextBox1.Text = ="") richTextBox1.Text= Checkbox2.text;//assign a value to a text box ElserichTextBox1.Text+=","+Checkbox2.text; } } //Select the ping- pong ball check box Private voidCheckbox3_checkedchanged (Objectsender, EventArgs e) { if(checkbox3.checked)//determine if CheckBox3 is selected { if(richTextBox1.Text = ="") richTextBox1.Text= Checkbox3.text;//assign a value to a text box ElserichTextBox1.Text+=","+Checkbox3.text; } } }}
CheckBox and RichTextBox