23. check box controls
The check box and the radio box are similar, that is, you can select multiple options.
1. Common Properties.
The A.text property. Description text.
The B.check property. True indicates that the selection is on.
The C.checkstate property that reflects the status of the check box.
2. Responding to events.
A.click event.
B.checkchanged event.
C.checkstatechanged event.
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;
Namespace WindowsFormsApplication8
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Label1_click (object sender, EventArgs e)
{
}
private void Button2_Click (object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show ("Do you want to quit? "," hint ", Messageboxbuttons.yesno, messageboxicon.warning);
if (dr = = Dialogresult.yes)
{
This. Close ();
}
}
private void Checkbox1_checkedchanged (object sender, EventArgs e)
{
}
private void Button1_Click (object sender, EventArgs e)
{
String struser = String. Empty;
struser = "Name" + TextBox1.Text + "\ n";
struser = struser + "hobby:" + (checkbox1.checked?) Music ":") +
(checkbox2.checked?) "Sports": "") +
(checkbox3.checked?) "Film": "");
DialogResult dr = MessageBox.Show (struser, "Information confirmation", Messageboxbuttons.okcancel,messageboxicon.information, Messageboxdefaultbutton.button1);
if (dr = = DialogResult.OK)
{
Textbox1.clear ();
checkbox1.checked = false;
checkbox2.checked = false;
checkbox3.checked = false;
}
}
private void Textbox1_validating (object sender, CancelEventArgs e)
{
if (textBox1.Text.Trim () = = string. Empty)
{
MessageBox.Show ("Name is empty, please re-enter!") " );
Textbox1.focus ();
}
}
private void Button2_mouseenter (object sender, EventArgs e)
{
Textbox1.causesvalidation = false;
}
private void Button2_mouseleave (object sender, EventArgs e)
{
Textbox1.causesvalidation = true;
}
}
}
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/60/46/wKiom1UqhS3j-38IAAD3dQ_x004652.jpg "title=" Kv7xn2yp ' vo{v] ' 2~ts$p]6.png "alt=" Wkiom1uqhs3j-38iaad3dq_x004652.jpg "/>
This article from "Very blog" blog, reproduced please contact the author!
C # Self-study Road 23