C # Use of the list box, check box, and combo box

Source: Internet
Author: User

Function implementation:
Implementation Code: 1> declare related variable storage major, Course settings and related information: [csharp] string gr, msg, xy; string [] spec, cour1, cour2, cour3, cour4, cour5; 2> In the Form1 class, the self-defined function bool checkGR () Checks student information: [csharp] private bool checkGR () {bool check = true; if (textBox1.Text. trim () = "" | textBox2.Text. trim () = "") {check = false; MessageBox. show ("name and age required");} return check;} 3> In the Form1 class, use the custom function string record () to collect student information: [csharp] private string record () {gr = ""; Gr + = textBox1.Text. trim (); if (radioButton1.Checked) gr + = ", male"; else gr + = ", female"; gr + = "," + textBox2.Text. trim () + "years old,"; string holobby = ""; foreach (Control ct1 in groupBox1.Controls) {CheckBox chk = (CheckBox) ct1; if (chk. checked = true) {holobby + = "<" + chk. text + ">" ;}}if (holobby! = "") {Holobby = "specialty" + holobby;} gr + = holobby; gr + = ". \ n "; xy =" Major <"+ comboBox1.Text +">. \ n required courses include: "; foreach (object course in listBox1.Items) {xy + =" <"+ course. toString () + ">";} xy + = ". \ N "; if (checkedListBox1.CheckedItems. Count! = 0) {xy + = "Note:"; foreach (object intr in checkedListBox1.CheckedItems) {xy + = "<" + intr. toString () + ">"; xy + = ". ";}} Msg + = gr + xy; return msg;} 4> Load event handler code: [csharp] private void form=load (object sender, EventArgs e) {radioButton1.Checked = true; spec = new string [5] {"computer", "software", "network", "Iot", "communication"}; comboBox1.DataSource = spec; comboBox1.SelectedIndex = 0; cour1 = new string [] {"Computer Application", "Program Design", "Database", "OPP", "Network Design", "Family Planning "}; cour2 = new string [] {"Computer Application", "programming", "Database", "OPP", "Network Design", "advanced programming "}; cour3 = new string [] {"Computer Application", "programming", "wireless network security", "OPP", "protocol analysis", "Jike "}; cour4 = new string [] {"Computer Application", "programming", "Computer mathematics", "Digital Media", "Computer Network", "Computer Science "}; cour5 = new string [] {"Computer Application", "digital power", "model power", "Mathematics", "communication", "Computer Science"}; listBox1.DataSource = cour1 ;} 5> code design of the combo box: [csharp] private void combobox?selectedindexchanged (object sender, EventArgs e) {switch (comboBox1.SelectedIndex) {case 0: listBox1.DataSource = cour1; break; case 1: listBox1.DataSource = cour2; break; case 2: listBox1.DataSource = cour3; break; case 3: listBox1.DataSource = cour4; break; case 4: listBox1.DataSource = cour5; break ;}} 6> confirm the Button code: [csharp] private void button#click (object sender, EventArgs e) {if (checkGR () {MessageBox. show (record (), textBox1.Text + "");} 7> exit the Button code: [csharp] private void button2_Click (object sender, EventArgs e) {this. close ();}

Related Article

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.