c#实验三
实验要求:自己设计并编写一个 Windows 应用程序,要求用到 TextBox、GroupBox、RadioButton、CheckBox、ComboBox、ListBox 控件。将程序功能、界面布局和运行结果的截图与事件代码写在实验报告中。
运行结果:
其中点击保存按钮会将个人简历中的内容保存到本地的Word文件中,点击载入按钮会将修改后的个人简历内容加载到本地Word文件中。
事件代码:
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 WindowsFormsApplication2 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void label1_Click(object sender, EventArgs e) 21 { 22 23 } 24 25 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 26 { 27 28 } 29 //radioButton1的Checked属性值改变时,触发radioButton1_CheckedChanged事件 30 private void radioButton1_CheckedChanged(object sender, EventArgs e) 31 { 32 if (radioButton1.Checked == true) 33 { 34 richTextBox1.Text += "性别:" + radioButton1.Text + "\n"; 35 } 36 } 37 38 private void radioButton2_CheckedChanged(object sender, EventArgs e) 39 { 40 if (radioButton2.Checked == true) 41 { 42 richTextBox1.Text += "性别:" + radioButton2.Text + "\n"; 43 } 44 } 45 46 private void textBox1_TextChanged(object sender, EventArgs e) 47 { 48 49 } 50 //textBox1中有键按下时,触发textBox1_KeyPress事件 51 private void textBox1_KeyPress_1(object sender, KeyPressEventArgs e) 52 { 53 if (e.KeyChar == 13) //如果键入回车键,则向richTextBox1中添加姓名 54 richTextBox1.Text += "姓名:" + textBox1.Text + "\n"; 55 } 56 57 private void radioButton3_CheckedChanged(object sender, EventArgs e) 58 { 59 if (radioButton3.Checked == true) 60 { 61 richTextBox1.Text += "学位:" + radioButton5.Text + "\n"; 62 } 63 } 64 65 private void radioButton5_CheckedChanged(object sender, EventArgs e) 66 { 67 if (radioButton5.Checked == true) 68 { 69 richTextBox1.Text += "学位:" + radioButton5.Text + "\n"; 70 } 71 } 72 73 private void radioButton4_CheckedChanged(object sender, EventArgs e) 74 { 75 if (radioButton4.Checked == true) 76 { 77 richTextBox1.Text += "性别:" + radioButton4.Text + "\n"; 78 } 79 } 80 81 private void checkBox1_CheckedChanged(object sender, EventArgs e) 82 { 83 if (checkBox1.Checked == true) 84 richTextBox1.Text += "爱好" + checkBox1.Text + "\n"; 85 } 86 87 private void checkBox2_CheckedChanged(object sender, EventArgs e) 88 { 89 if (checkBox2.Checked == true) 90 richTextBox1.Text += "爱好" + checkBox2.Text + "\n"; 91 } 92 93 private void checkBox3_CheckedChanged(object sender, EventArgs e) 94 { 95 if (checkBox3.Checked == true) 96 richTextBox1.Text += "爱好" + checkBox3.Text + "\n"; 97 } 98 99 private void comboBox1_KeyPress(object sender, KeyPressEventArgs e) 100 { 101 if ((e.KeyChar == 13) && comboBox1.Text != "") 102 richTextBox1.Text += "班级:" + comboBox1.Text + "\n"; 103 } 104 105 private void listBox1_SelectedIndexChanged(object sender, EventArgs e) 106 { 107 richTextBox1.Text += "专业:" + listBox1.SelectedItem + "\n"; 108 } 109 110 private void button1_Click(object sender, EventArgs e) 111 { 112 richTextBox1.Clear(); 113 } 114 115 116 //复制 117 private void button4_Click(object sender, EventArgs e) 118 { 119 richTextBox1.Copy(); 120 } 121 122 private void button5_Click(object sender, EventArgs e) 123 { 124 richTextBox1.Paste(); 125 } 126 127 //前面加入@防止转义 128 //保存文件 129 //路径 130 private void button3_Click(object sender, EventArgs e) 131 { 132 133 richTextBox1.SaveFile(@"F:\xinxi.rtf",RichTextBoxStreamType.RichText); 134 } 135 //loadfile作用 136 private void button2_Click(object sender, EventArgs e) 137 { 138 // richTextBox1.LoadFile("F:\vsProject\xinxi.rft",RichTextBoxStreamType.RichText); 139 richTextBox1.LoadFile(@"F:\xinxi.rtf",RichTextBoxStreamType.RichText); 140 141 } 142 143 private void Form1_Load(object sender, EventArgs e) 144 { 145 richTextBox1.Clear(); 146 timer3.Interval = 1000;//设置Interval 属性为1000毫秒 147 } 148 149 private void textBox2_TextChanged(object sender, EventArgs e) 150 { 151 } 152 153 private void timer1_Tick(object sender, EventArgs e) 154 { 155 // 156 157 } 158 159 160 161 private void timer3_Elapsed(object sender, System.Timers.ElapsedEventArgs e) 162 { 163 textBox2.Text = DateTime.Now.ToString(); 164 165 } 166 167 168 169 } 170 }