C # Self-study Road 23

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.