2021/11/1
一、任务
自己设计并编写一个 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.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace students_tutorial3_2 12 { 13 public partial class add_student : Form 14 { 15 public String name; 16 public String kemu; 17 public String score; 18 public String id; 19 public String sex; 20 public String guake; 21 22 public add_student() 23 { 24 InitializeComponent(); 25 } 26 private void add_Click(object sender, EventArgs e) 27 { 28 29 /*string[] subject = new[]{ "高数", "线性代数", "离散数学", 30 "数据结构", "概率论", "马克思原理", 31 "数据库原理" }; 32 comboBox1.DataSource = subject;*/ 33 kemu = comboBox1.Text; 34 listStu.name2 = name; 35 listStu.id2 = id; 36 listStu.sex2 = sex; 37 listStu.guake2 = guake; 38 listStu.kemu2 = kemu; 39 40 listStu tc = new listStu(); 41 tc.Show(); 42 43 44 } 45 46 private void text_name_TextChanged(object sender, EventArgs e) 47 { 48 name = text_name.Text.ToString(); 49 } 50 51 private void text_sid_TextChanged(object sender, EventArgs e) 52 { 53 id = text_sid.Text.ToString(); 54 } 55 56 private void groupBox1_Enter(object sender, EventArgs e) 57 { 58 sex = (String)(this.radioButton1.Checked ? "女" : "男"); 59 } 60 61 private void checkBox1_CheckedChanged(object sender, EventArgs e) 62 { 63 bool b1 = checkBox1.Checked; 64 65 66 if (b1) 67 { 68 guake = "是"; 69 } 70 else 71 { 72 guake = "否"; 73 } 74 75 } 76 77 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 78 { 79 string[] subject = new[]{ "高数", "线性代数", "离散数学", 80 "数据结构", "概率论", "马克思原理", 81 "数据库原理" }; 82 comboBox1.DataSource = subject; 83 kemu = comboBox1.Text; 84 } 85 86 private void grade_TextChanged(object sender, EventArgs e) 87 { 88 score = grade.Text; 89 } 90 91 } 92 } add.CS
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.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace students_tutorial3_2 12 { 13 public partial class listStu : Form 14 { 15 static public String guake2; 16 static public String name2; 17 static public String id2; 18 static public String sex2; 19 20 public listStu() 21 { 22 InitializeComponent(); 23 24 25 textBox1.Text = name2; 26 27 if ( guake2== "是") 28 { 29 String str = name2 + " " + id2 + " " + sex2; 30 listBox1.Items.Add(str); 31 } 32 else if (guake2 == "否") 33 { 34 String str = name2 + " " + id2 + " " + sex2 ; 35 listBox2.Items.Add(str); 36 } 37 38 string msg = ""; 39 for (int i = 0; i < listBox1.SelectedItems.Count; i++) 40 { 41 msg = msg + " " + listBox1.SelectedItems[i].ToString(); 42 } 43 44 } 45 46 private void listBox1_SelectedIndexChanged(object sender, EventArgs e) 47 { 48 // add_student a = new add_student(); 49 50 51 52 } 53 54 private void left_Click(object sender, EventArgs e) 55 { 56 int count = listBox2.SelectedItems.Count; 57 List<string> itemValues = new List<string>(); 58 if (count != 0) 59 { 60 for (int i = 0; i < count; i++) 61 { 62 itemValues.Add(listBox2.SelectedItems[i].ToString()); 63 } 64 foreach (string item in itemValues) 65 { 66 listBox2.Items.Remove(item); 67 listBox1.Items.Add(item); 68 69 70 } 71 } 72 else 73 { 74 MessageBox.Show("请选择需要移动的人员!"); 75 } 76 77 78 } 79 80 private void right_Click(object sender, EventArgs e) 81 { 82 int count = listBox1.SelectedItems.Count; 83 List<string> itemValues = new List<string>(); 84 if (count != 0) 85 { 86 for (int i = 0; i < count; i++) 87 { 88 itemValues.Add(listBox1.SelectedItems[i].ToString()); 89 } 90 foreach (string item in itemValues) 91 { 92 listBox1.Items.Remove(item); 93 listBox2.Items.Add(item); 94 95 96 } 97 } 98 else 99 { 100 MessageBox.Show("请选择需要移动的人员!"); 101 } 102 103 } 104 105 private void textBox1_TextChanged(object sender, EventArgs e) 106 { 107 108 } 109 110 111 } 112 }