自己设计并编写一个 Windows 应用程序,要求用到 TextBox、GroupBox、 RadioButton、CheckBox、ComboBox、ListBox 控件。

自己设计并编写一个 Windows 应用程序,要求用到 TextBox、GroupBox、

 

RadioButton、CheckBox、ComboBox、ListBox 控件。将程序功能、界面布局和运行结果

 

的截图与事件代码写在实验报告中。

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. namespace WindowsFormsApplication2  
  10. {  
  11. public partial class Form1 : Form  
  12. {  
  13. public Form1()  
  14. {  
  15. InitializeComponent();  
  16. this.comboBox1.Items.Add("团员");  
  17. this.comboBox1.Items.Add("群众");  
  18. this.comboBox1.Items.Add("预备党员");  
  19. this.comboBox1.Items.Add("党员");  
  20. this.comboBox2.Items.Add("信息科学与技术学院");  
  21. this.comboBox2.Items.Add("土木学院");  
  22. this.comboBox2.Items.Add("经济管理学院");  
  23. this.comboBox2.Items.Add("电气学院");  
  24. this.comboBox2.Items.Add("文法学院");  
  25. }  
  26. private void button1_Click(object sender, EventArgs e)  
  27. {  
  28. string msg = "";  
  29. msg = "姓名:" + textBox1.Text+"学号:"+textBox2.Text+"性别:";  
  30. if (radioButton1.Checked)  
  31. {  
  32. msg = msg+radioButton1.Text;  
  33. }  
  34. else if (radioButton2.Checked)  
  35. {  
  36. msg = radioButton2.Text;  
  37. }  
  38. msg = msg + "政治面貌" + this.comboBox1.SelectedItem.ToString();  
  39. msg = msg + "院系" + this.comboBox2.SelectedItem.ToString()+"爱好:";  
  40. if (checkBox1.Checked)  
  41. {  
  42. msg = msg + " " + checkBox1.Text;  
  43. }  
  44. if (checkBox2.Checked)  
  45. {  
  46. msg = msg + " " + checkBox2.Text;  
  47. }  
  48. if (checkBox3.Checked)  
  49. {  
  50. msg = msg + " " + checkBox3.Text;  
  51. }  
  52. if (checkBox4.Checked)  
  53. {  
  54. msg = msg + " " + checkBox4.Text;  
  55. }  
  56. MessageBox.Show(msg);  
  57. }  
  58. private void button2_Click(object sender, EventArgs e)  
  59. {  
  60. Application.Exit();  
  61. }  
  62. private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)  
  63. {  
  64. comboBox3.Items.Clear();  
  65. if (comboBox2.Text == "信息科学与技术学院")  
  66. {  
  67. comboBox3.Items.Add("信1905-1班");  
  68. comboBox3.Items.Add("信1905-2班");  
  69. }  
  70. if (comboBox2.Text == "土木学院")  
  71. {  
  72. comboBox3.Items.Add("土1905-1班");  
  73. comboBox3.Items.Add("土1905-2班");  
  74. }  
  75. if (comboBox2.Text == "文法学院")  
  76. {  
  77. comboBox3.Items.Add("文1905-1班");  
  78. comboBox3.Items.Add("文1905-2班");  
  79. }  
  80. if (comboBox2.Text == "经济管理学院")  
  81. {  
  82. comboBox3.Items.Add("经1905-1班");  
  83. comboBox3.Items.Add("经1905-2班");  
  84. }  
  85. if (comboBox2.Text == "电气学院")  
  86. {  
  87. comboBox3.Items.Add("电1905-1班");  
  88. comboBox3.Items.Add("电1905-2班");  
  89. }  
  90. }       
  91. }  
  92. }  

 

posted @ 2021-11-17 03:13  小跳不磕脑袋  阅读(260)  评论(0编辑  收藏  举报