const int spi = 100;
const int mpi = 75;
const int hpi = 50;
private void Clock(int h, int m, int s)
{
Graphics graphice = pictureBox1.CreateGraphics();
graphice.Clear(Color.White);
Pen pen = new Pen(Color.Black, 1);
graphice.DrawEllipse(pen, pictureBox1.ClientRectangle);
Point cp = new Point(pictureBox1.ClientRectangle.Width / 2, pictureBox1.ClientRectangle.Height / 2);
Point sp = new Point((int)(cp.X + (Math.Sin(6 * s * Math.PI / 180)) * spi), (int)(cp.Y - (Math.Cos(6 * s * Math.PI / 180)) * spi));
Point mp = new Point((int)(cp.X + (Math.Sin(6 * m * Math.PI / 180)) * mpi), (int)(cp.Y - (Math.Cos(6 * m * Math.PI / 180)) * mpi));
Point hp = new Point((int)(cp.X + (Math.Sin(6 * h * Math.PI / 180)) * hpi), (int)(cp.Y - (Math.Cos(6 * h * Math.PI / 180)) * hpi));
graphice.DrawLine(pen, cp, sp);
pen = new Pen(Color.Black, 2);
graphice.DrawLine(pen, cp, mp);
pen = new Pen(Color.Black, 4);
graphice.DrawLine(pen, cp, hp);
}
private void timer1_Tick(object sender, EventArgs e)
{
int h = DateTime.Now.Hour;
int m = DateTime.Now.Minute;
int s = DateTime.Now.Second;
Clock(h, m, s);
statusStrip1.Text = "當前時間: " + DateTime.Now.ToLongTimeString();
}
Clock繪製