1: public class ClockFaceCtrl : System.Windows.Forms.Control
2: { 3: public ClockFaceCtrl()
4: { } 5:
6: public void OnTimer(Object source, ElapsedEventArgs e)
7: { 8: Graphics g = this.CreateGraphics();
9: SetScale(g);
10: DrawFace(g);
11: DrawTime(g,false);
12: DrawDate(g);
13: g.Dispose();
14: }
15:
16: protected override void OnPaint ( PaintEventArgs e )
17: { } 18:
19: private void SetScale(Graphics g)
20: { 21: g.TranslateTransform(Width / 2, Height / 2);
22: float inches = Math.Min(Width / g.DpiX, Height / g.DpiX);
23: g.ScaleTransform(inches * g.DpiX / 2000, inches * g.DpiY / 2000);
24: }
25:
26: private static float GetSin(float degAngle)
27: { return (float) Math.Sin(Math.PI * degAngle / 180f); } 28:
29: private static float GetCos(float degAngle)
30: { return (float) Math.Cos(Math.PI * degAngle / 180f); } 31:
32: private void DrawFace(Graphics g)
33: { 34: for (int i = 1; i <= numHours; i++)
35: { 36: SizeF stringSize = g.MeasureString(i.ToString(),font);
37: x = GetCos(i*deg + 90) * FaceRadius;
38: y = GetSin(i*deg + 90) * FaceRadius;
39: if ( currentTime.Second == i * 5)
40: g.DrawString(i.ToString(), font, greenBrush, -x, -y,format);
41: else
42: g.DrawString(i.ToString(), font, brush, -x, -y,format);
43: }
44: }
45:
46: private void DrawTime(Graphics g, bool forceDraw)
47: { 48: rotation = GetSecondRotation();
49: state = g.Save();
50: g.RotateTransform(rotation);
51: g.FillEllipse(blankBrush,-25,-secondLength,50,50);
52: g.Restore(state);
53: }
54:
55: private float GetHourRotation()
56: { } 57: private float GetMinuteRotation()
58: { return( 360f * currentTime.Minute / 60f ); } 59:
60: private float GetSecondRotation()
61: { return(360f * currentTime.Second / 60f); } 62:
63: private class LtrDraw
64: { } 65:
66: private class StringDraw
67: { 68: public StringDraw(string s, ClockFaceCtrl theControl)
69: { } 70:
71: public void DrawString(Graphics g, Brush brush)
72: { 73: foreach (LtrDraw theLtr in theString)
74: { 75: theLtr.DrawString(g,brush,theControl);
76: }
77: ClockFaceCtrl.offset += 1;
78: }
79: }
80:
81: private void DrawDate(Graphics g)
82: { 83: Brush brush = new SolidBrush(ForeColor);
84: sdToday.DrawString(g,brush);
85: }
86: }