01windows窗體程序學習,01windows窗體程序
1
2
3 靜態用戶名和密碼的登錄練習
4
5 private void button2_Click(object sender, EventArgs e)
6 {
7
8 textUser.Text = Convert.ToString(textUser.Text);
9 textBox2.Text = textBox2.Text.ToString();
10 if (textUser.Text == "admin" && textBox2.Text == "111111")
11 {
12 MessageBox.Show("登錄成功");
13 }
14 else
15 {
16 MessageBox.Show("用戶名或密碼錯誤");
17 }
18
19 }
20
21
22
23 窗體關閉消息提示的練習
24
25 private void Form2_FormClosing(object sender, FormClosingEventArgs e)
26 {
27 DialogResult re = MessageBox.Show("確定關閉?","消息",MessageBoxButtons.YesNo);//是否關閉消息提示框
28 if (re == DialogResult.No)
29 {
30 e.Cancel = true; //關閉
31 }
32 else
33 {
34 e.Cancel = false; //不關閉
35 }
36 }
37
38