
新增一個windows form application
同時加入一個新的類別檔案



1: // 訂閱者
2: public interface iObserver
3: {4: void Update();
5: }6: // 主題
7: public interface iSubject
8: {9: void Add(iObserver observer); // 加入一個訂閱者
10: void Delete(iObserver observer); // 刪除一個訂閱者
11: void Notify(); // 通知訂閱者
12: }Set the BorderStyle to FixedSingle.
Set the Text to the digit 0 (zero).
Set the Autosize to False.
Set the Size to 30, 20.
Set the TextAlign to MiddleCenter.




1: public sealed class tictoc
2: {3: private DateTime startTime;
4: private static tictoc manager; // Singleton物件: tictoc類別的唯一物件
5: // 靜態建構子
6: static tictoc()
7: { 8: 9: }10: // 預設建構子
11: private tictoc()
12: { 13: startTime = DateTime.Now; 14: }15: // 靜態方法
16: public static tictoc Instance
17: { 18: get 19: {20: if (manager == null)
21: {22: manager = new tictoc();// 呼叫預設建構子並初始化startTime
23: }24: return manager;
25: } 26: }
1: #region 設定滑鼠位置
2: [DllImport("user32.dll")]
3: public static extern bool SetCursorPos(int x, int y);
4: #endregion
5: #region 模擬滑鼠事件
6: [DllImport("user32.dll")]
7: public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
8: public const int MOUSEEVENTF_LEFTDOWN = 0x02;
9: public const int MOUSEEVENTF_LEFTUP = 0x04;
10: #endregion