2 Border Style Border Style label 1 3
2. Border. Style (邊框)的列舉型別為Border. Style [例] 將 label 1 控制項邊框設成 3 D立體框線,寫法: label 1. Border. Style = Border. Style. Fixed 3 D;
3. Text. Align 文字對齊方式的列舉型別為 Content. Alignment:
編寫程式碼 private void Form 1_Activated(object sender, Event. Args e) { this. Text = "Activated 事件"; this. Location = new Point(50, 50); this. Size = new Size(300, 200); this. Back. Color = Color. Green; } private void Form 1_Click(object sender, Event. Args e) { this. Text = "Click 事件"; this. Back. Color = Color. White; }
private void Form 1_Load(object sender, Event. Args e) { lbl. Show. Text. Align = Content. Alignment. Middle. Center; lbl. Show. Text = "輸入密碼後,按 [檢查] 鈕"; txt. PW. Max. Length = 8; txt. PW. Password. Char = '*'; txt. PW. Text = ""; txt. Money. Enabled = false; btn. Ok. Enabled = false; } private void btn. Check_Click(object sender, Event. Args e) { if (txt. PW. Text == "123456") { btn. Ok. Enabled = true; txt. Money. Focus(); lbl. Show. Text = "輸入提領金額,按 [確定] 鈕"; } else { lbl. Show. Text = "密碼錯誤!重新輸入"; txt. PW. Clear(); } } private void btn. Ok_Click(object sender, Event. Args e) { lbl. Show. Text = "提領金額是 " + txt. Money. Text + " 元"; } private void btn. Cancel_Click(object sender, Event. Args e) { Form 1_Load(sender, e); }
6 -8 Message. Box 類別
一. Message. Box. Show 方法
寫法: Message. Box. Show("心美,看什麼都漂亮!", "開朗", Message. Box. Buttons. Yes. No, Message. Box. Icon. Asterisk);
三、Message. Box. Show 方法的傳回值
private void Form 1_Load(object sender, Event. Args e) { tool. Tip 1. Set. Tool. Tip(txt. N 1, "請輸入 1~100的整數!"); tool. Tip 1. Set. Tool. Tip(txt. N 2, "請輸入 1~100的整數!"); } private void btn. LCM_Click(object sender, Event. Args e) { int n 1, n 2, max, min, remainder; try { n 1 = int. Parse(txt. N 1. Text); } catch { Message. Box. Show("第一格請輸入整數值!", "錯誤", Message. Box. Buttons. OK, Message. Box. Icon. Hand); return; } try { n 2 = int. Parse(txt. N 2. Text); } catch { Message. Box. Show("第二格請輸入整數值!", "錯誤", Message. Box. Buttons. OK, Message. Box. Icon. Hand); return; } if (n 1 < 1 || n 1 > 100) { Message. Box. Show("第一格請輸入 1~100的整數!", "錯誤", Message. Box. Buttons. OK, Message. Box. Icon. Hand); return; } if (n 2 < 1 || n 2 > 100) { Message. Box. Show("第二格請輸入 1~100的整數!", "錯誤", Message. Box. Buttons. OK, Message. Box. Icon. Hand); return; } if (n 2 > n 1) { max = n 2; min = n 1; } else { max = n 1; min = n 2; } do { remainder = max % min; if (remainder == 0) break; max = min; min = remainder; } while (true); lbl. LCM. Text = n 1 + " 和 " + n 2 + " 的最大公因數是 " + min; } private void btn. Reset_Click(object sender, Event. Args e) { txt. N 1. Text = ""; txt. N 2. Text = ""; lbl. LCM. Text = ""; } private void btn. Exit_Click(object sender, Event. Args e) { Application. Exit(); }
- Slides: 79