Presentation is loading. Please wait.

Presentation is loading. Please wait.

多樂一甲 謝佩臻 4A3K0009.

Similar presentations


Presentation on theme: "多樂一甲 謝佩臻 4A3K0009."— Presentation transcript:

1 多樂一甲 謝佩臻 4A3K0009

2 【時鐘 】 依照現在時間,時針、分針 及 秒針會指向正確的時間,顯示在時鐘面板上。 【日期 及 時間】 日期:年分/月份/日 時間:上(下)午 時:分:秒

3 時鐘的function private void timer1_Tick(object sender, EventArgs e) {
//建一個時鐘 g = Graphics.FromImage(bmp); //取得現在的時間(秒鐘、分鐘、時) int ss = DateTime.Now.Second; int mm = DateTime.Now.Minute; int hh = DateTime.Now.Hour; int[] handCoord = new int[2]; //時鐘的背景顏色 g.Clear(Color.SkyBlue); //畫時鐘的外框 g.DrawEllipse(new Pen(Color.DeepPink, 1f), 0, 0, WIDTH, HEIGHT);

4 //畫時鐘面板上的數字(12、3、6、9) g.DrawString("12", new Font("Arial", 12), Brushes.DeepPink, new PointF(140, 2)); g.DrawString("3", new Font("Arial", 12), Brushes.DeepPink, new PointF(286, 140)); g.DrawString("6", new Font("Arial", 12), Brushes.DeepPink, new PointF(142, 282)); g.DrawString("9", new Font("Arial", 12), Brushes.DeepPink, new PointF(0, 140)); //畫秒針 handCoord = msCoord(ss, secHAND); g.DrawLine(new Pen(Color.Red, 1f), new Point(cx, cy), new Point(handCoord[0], handCoord[1])); //畫分針 handCoord = msCoord(mm, minHAND); g.DrawLine(new Pen(Color.Black, 2f), new Point(cx, cy), new Point(handCoord[0], handCoord[1])); //畫時針 handCoord = hrCoord(hh % 12, mm, hrHAND); g.DrawLine(new Pen(Color.Gray, 3f), new Point(cx, cy), new Point(handCoord[0], handCoord[1]));

5 //將時鐘載入picturebox1裡面 pictureBox1.Image = bmp; //視窗標題內容 this.Text = "Analog Clock - " + hh + ":" + mm + ":" + ss; //處理 g.Dispose(); }

6 //設定調整分針和秒針 private int[] msCoord(int val, int hlen) { int[] coord = new int[2]; val *= 6; //每分鐘分針和每秒鐘秒針移動6度 if (val >= 0 && val <= 180) coord[0] = cx + (int)(hlen * Math.Sin(Math.PI * val / 180)); coord[1] = cy - (int)(hlen * Math.Cos(Math.PI * val / 180)); } else coord[0] = cx - (int)(hlen * -Math.Sin(Math.PI * val / 180)); return coord;

7 //設定調整時針 private int[] hrCoord(int hval, int mval, int hlen) { int[] coord = new int[2]; //每小時時針移動30度 //每分鐘時針移動0.5度 int val = (int)((hval * 30) + (mval * 0.5)); if (val >= 0 && val <= 180) coord[0] = cx + (int)(hlen * Math.Sin(Math.PI * val / 180)); coord[1] = cy - (int)(hlen * Math.Cos(Math.PI * val / 180)); } else coord[0] = cx - (int)(hlen * -Math.Sin(Math.PI * val / 180)); return coord;

8 日期和時間的function private void timer2_Tick(object sender, EventArgs e) {
DateTime dt = DateTime.Now; string Today; Today = DateTime.Now.ToString(); //日期時間模式 2009/8/24 下午 08:09:42 label1.Text = String.Format(“[現在時間] {0} 日期:{1}", "", Today);


Download ppt "多樂一甲 謝佩臻 4A3K0009."

Similar presentations


Ads by Google