1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | 參照 namespace _103303058_0518_01 { public enum Sport { NONE, BASEBALL, TENNIS, FOOTBALL, BASKETBALL, }; public class C_Person { public string Name = "未輸入"; //在每個變數前說明私密於否 public Sport Favorate_Sport = Sport.NONE; } } 設計者 /// 設計工具所需的變數。 private C_Person David; /// </summary> namespace _103303058_0518_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { David = new C_Person(); listBox_Favorate.SelectedIndex = (int)David.Favorate_Sport; pictureBox1.Image = Image.FromFile("None.jpg"); textBox1.Text = David.Name; } private void listBox_Favorate_SelectedIndexChanged(object sender, EventArgs e) { switch ((Sport)listBox_Favorate.SelectedIndex) { case Sport.NONE: pictureBox1.Image = Image.FromFile("None.jpg"); break; case Sport.BASEBALL: pictureBox1.Image = Image.FromFile("Baseball.jpg"); break; case Sport.BASKETBALL: pictureBox1.Image = Image.FromFile("Basketball.jpg"); break; case Sport.FOOTBALL: pictureBox1.Image = Image.FromFile("Football.jpg"); break; case Sport.TENNIS: pictureBox1.Image = Image.FromFile("Tennis.jpg"); break; } } private void pictureBox2_Click(object sender, EventArgs e) { string str; str = "你的姓名是" + textBox1.Text; switch ((Sport)listBox_Favorate.SelectedIndex) { case Sport.NONE: str += "\n你不喜歡運動"; break; case Sport.BASEBALL: str += "\n你最喜歡的運動是棒球"; break; case Sport.BASKETBALL: str += "\n你最喜歡的運動是籃球"; break; case Sport.FOOTBALL: str += "\n你最喜歡的運動是足球"; break; case Sport.TENNIS: str += "\n你最喜歡的運動是網球"; break; } MessageBox.Show(str, "生日&最喜歡運動", MessageBoxButtons.OK); } private void textBox1_TextChanged(object sender, EventArgs e) { } } } |
Direct link: https://paste.plurk.com/show/HjSSNY5Ub20MjnNiSiIQ