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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | 參照 namespace HW9_1 { enum Sports { NONE, //順序需與ListBox一致 BASEBALL, TENNIS, BASKETBALL, FOOTBALL }; class CPerson { public String Name = "無名氏"; //新增姓名欄位 public Sports FavoriteSport = Sports.NONE; //新增最愛運動欄位 public int AvailableHolidayDays = 0; public DateTime Birthday; private int mYearsofExperience = 0; private int mPermitHolidayDays = 0; public CPerson() { } public CPerson(String NameIn, Sports FavorateSportIn, DateTime BirthdayIn) { Name = NameIn; FavoriteSport = FavorateSportIn; Birthday = BirthdayIn; } public string HappyBirthdayInfo() { return Name + "您的生日是" + Birthday.ToShortDateString() + "\n預先祝您生日快樂"; } public int YearsofExperience { get //讀取屬性值 { return mYearsofExperience; } set //設定屬性值 { if (value > 40) mYearsofExperience = 40; else if (value < 1) mYearsofExperience = 1; else mYearsofExperience = value; } } public int PermitHolidayDays { get //讀取屬性值 { return mPermitHolidayDays; } set { if(YearsofExperience <= 1) AvailableHolidayDays = 1; else if(YearsofExperience <= 5) AvailableHolidayDays = 3; else if (YearsofExperience <= 10) AvailableHolidayDays = 5; else if (YearsofExperience <= 20) AvailableHolidayDays = 14; else AvailableHolidayDays = 21; if(value > AvailableHolidayDays) mPermitHolidayDays = AvailableHolidayDays; else if(value < 1) mPermitHolidayDays = 1; else mPermitHolidayDays = value; } } } } 設計者 /// <summary> /// 設計工具所需的變數。 /// </summary> private System.ComponentModel.IContainer components = null; private CPerson David; int Move; using HW9_1; namespace _103303058_0601_02 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { David = new CPerson("王曉明", Sports.BASEBALL, new DateTime(1999,12,07)); textBox1.Text = David.Name; dateTimePicker1.Value = David.Birthday; Move = 0; label3.Text = David.HappyBirthdayInfo(); if (timerRunner.Enabled) { timerRunner.Stop(); } else { timerRunner.Start(); } } private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { David.Birthday = dateTimePicker1.Value ; label3.Text = David.HappyBirthdayInfo(); } private void timerRunner_Tick(object sender, EventArgs e) { label3.Location = new Point(Move, 165); if (Move >= this.Width) { Move = -label3.Width; } else { Move += 2; } } private void buttonStart_Click(object sender, EventArgs e) { timerRunner.Start(); } private void buttonEnd_Click(object sender, EventArgs e) { timerRunner.Stop(); } } } |
Direct link: https://paste.plurk.com/show/YGHt9U7581tNSc49obo1