<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2F2D%2FClock</id>
		<title>Csharp/CSharp Tutorial/2D/Clock - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2F2D%2FClock"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/2D/Clock&amp;action=history"/>
		<updated>2026-04-29T17:29:18Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/2D/Clock&amp;diff=6368&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/2D/Clock&amp;diff=6368&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/2D/Clock&amp;diff=6369&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/2D/Clock&amp;diff=6369&amp;oldid=prev"/>
				<updated>2010-05-26T12:18:52Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==our clock==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;/* Quote from &lt;br /&gt;
Programming .NET Windows Applications&lt;br /&gt;
By Jesse Liberty, Dan Hurwitz&lt;br /&gt;
First Edition October 2003 &lt;br /&gt;
Pages: 1246 (More details)&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Drawing.Drawing2D;&lt;br /&gt;
using System.Timers;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
public class Form1 : System.Windows.Forms.Form&lt;br /&gt;
{&lt;br /&gt;
  private System.ruponentModel.IContainer components;&lt;br /&gt;
  private int FaceRadius = 450;    // size of the clock face&lt;br /&gt;
  private bool b24Hours = false;    // 24 hour clock face?&lt;br /&gt;
  private System.Windows.Forms.Button btnClockFormat;&lt;br /&gt;
  private System.Windows.Forms.Timer timer1;        // center of the clock&lt;br /&gt;
  private DateTime currentTime;    // used in more than one method&lt;br /&gt;
  public Form1()&lt;br /&gt;
  {&lt;br /&gt;
    // Required for Windows Form Designer support&lt;br /&gt;
    InitializeComponent();&lt;br /&gt;
    // use the user&amp;quot;s choice of colors&lt;br /&gt;
    BackColor = SystemColors.Window;&lt;br /&gt;
    ForeColor = SystemColors.WindowText;&lt;br /&gt;
    timer1.Interval = 500;&lt;br /&gt;
    timer1.Enabled = true;&lt;br /&gt;
  }&lt;br /&gt;
  protected override void OnPaint ( PaintEventArgs e )&lt;br /&gt;
  {&lt;br /&gt;
    Graphics g = e.Graphics;&lt;br /&gt;
    SetScale(g);&lt;br /&gt;
    DrawFace(g);&lt;br /&gt;
    DrawTime(g,true);  // force an update&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  #region Windows Form Designer generated code&lt;br /&gt;
  protected override void Dispose( bool disposing )&lt;br /&gt;
  {&lt;br /&gt;
    if( disposing )&lt;br /&gt;
    {&lt;br /&gt;
      if (components != null) &lt;br /&gt;
      {&lt;br /&gt;
        components.Dispose();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    base.Dispose( disposing );&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  /// &amp;lt;summary&amp;gt;&lt;br /&gt;
  /// Required method for Designer support - do not modify&lt;br /&gt;
  /// the contents of this method with the code editor.&lt;br /&gt;
  /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
  private void InitializeComponent()&lt;br /&gt;
  {&lt;br /&gt;
    this.ruponents = new System.ruponentModel.Container();&lt;br /&gt;
    this.btnClockFormat = new System.Windows.Forms.Button();&lt;br /&gt;
    this.timer1 = new System.Windows.Forms.Timer(this.ruponents);&lt;br /&gt;
    this.SuspendLayout();&lt;br /&gt;
    // &lt;br /&gt;
    // btnClockFormat&lt;br /&gt;
    // &lt;br /&gt;
    this.btnClockFormat.Location = new System.Drawing.Point(8, 8);&lt;br /&gt;
    this.btnClockFormat.Name = &amp;quot;btnClockFormat&amp;quot;;&lt;br /&gt;
    this.btnClockFormat.TabIndex = 1;&lt;br /&gt;
    this.btnClockFormat.Text = &amp;quot;24 Hours&amp;quot;;&lt;br /&gt;
    this.btnClockFormat.Click += new System.EventHandler(this.btnClockFormat_Click);&lt;br /&gt;
    // &lt;br /&gt;
    // timer1&lt;br /&gt;
    // &lt;br /&gt;
    this.timer1.Tick += new System.EventHandler(this.timer1_Tick);&lt;br /&gt;
    // &lt;br /&gt;
    // Form1&lt;br /&gt;
    // &lt;br /&gt;
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
    this.ClientSize = new System.Drawing.Size(292, 266);&lt;br /&gt;
    this.Controls.AddRange(new System.Windows.Forms.Control[] {&lt;br /&gt;
                                    this.btnClockFormat});&lt;br /&gt;
    this.Name = &amp;quot;Form1&amp;quot;;&lt;br /&gt;
    this.Text = &amp;quot;Clock2CS&amp;quot;;&lt;br /&gt;
    this.ResumeLayout(false);&lt;br /&gt;
  }&lt;br /&gt;
  #endregion&lt;br /&gt;
  [STAThread]&lt;br /&gt;
  static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    Application.Run(new Form1());&lt;br /&gt;
  }&lt;br /&gt;
  private void SetScale(Graphics g)&lt;br /&gt;
  {&lt;br /&gt;
    // if the form is too small, do nothing&lt;br /&gt;
    if ( Width == 0 || Height == 0 )&lt;br /&gt;
      return;&lt;br /&gt;
    // set the origin at the center&lt;br /&gt;
    g.TranslateTransform(Width/2, Height/2);&lt;br /&gt;
    // set inches to the minimum of the width &lt;br /&gt;
    // or height dividedby the dots per inch  &lt;br /&gt;
    float inches = Math.Min(Width / g.DpiX, Height / g.DpiX);&lt;br /&gt;
    // set the scale to a grid of 2000 by 2000 units&lt;br /&gt;
    g.ScaleTransform(&lt;br /&gt;
      inches * g.DpiX / 2000, inches * g.DpiY / 2000);&lt;br /&gt;
  }&lt;br /&gt;
  private void DrawFace(Graphics g)&lt;br /&gt;
  {&lt;br /&gt;
    // numbers are in forecolor except flash number in green&lt;br /&gt;
    // as the seconds go by.&lt;br /&gt;
    Brush brush = new SolidBrush(ForeColor);&lt;br /&gt;
    Font font = new Font(&amp;quot;Arial&amp;quot;, 40);&lt;br /&gt;
    float x, y;&lt;br /&gt;
    // new code&lt;br /&gt;
    int numHours = b24Hours ? 24 : 12;&lt;br /&gt;
    int deg = 360 / numHours;&lt;br /&gt;
    &lt;br /&gt;
    // for each of the hours on the clock face&lt;br /&gt;
    for (int i = 1; i &amp;lt;= numHours; i++)&lt;br /&gt;
    {&lt;br /&gt;
      // i = hour  30 degrees = offset per hour  &lt;br /&gt;
      // +90 to make 12 straight up&lt;br /&gt;
      x = GetCos(i*deg + 90) * FaceRadius;&lt;br /&gt;
      y = GetSin(i*deg + 90) * FaceRadius;&lt;br /&gt;
      StringFormat format = new StringFormat();&lt;br /&gt;
      format.Alignment = StringAlignment.Center;&lt;br /&gt;
      format.LineAlignment = StringAlignment.Center;&lt;br /&gt;
      g.DrawString(&lt;br /&gt;
        i.ToString(), font, brush, -x, -y,format);&lt;br /&gt;
    &lt;br /&gt;
    }  // end for loop&lt;br /&gt;
  }    // end drawFace&lt;br /&gt;
&lt;br /&gt;
  private void DrawTime(Graphics g, bool forceDraw)&lt;br /&gt;
  {&lt;br /&gt;
    //  length of the hands&lt;br /&gt;
    float hourLength = FaceRadius * 0.5f;&lt;br /&gt;
    float minuteLength = FaceRadius * 0.7f;&lt;br /&gt;
    float secondLength = FaceRadius * 0.9f;&lt;br /&gt;
    // set to back color to erase old hands first&lt;br /&gt;
    Pen hourPen = new Pen(BackColor);&lt;br /&gt;
    Pen minutePen = new Pen(BackColor);&lt;br /&gt;
    Pen secondPen = new Pen(BackColor);&lt;br /&gt;
    // set the arrow heads&lt;br /&gt;
    hourPen.EndCap = LineCap.ArrowAnchor;&lt;br /&gt;
    minutePen.EndCap = LineCap.ArrowAnchor;&lt;br /&gt;
    // hour hand is thicker&lt;br /&gt;
    hourPen.Width = 30;&lt;br /&gt;
    minutePen.Width = 20;&lt;br /&gt;
    // second hand &lt;br /&gt;
    Brush secondBrush = new SolidBrush(BackColor);&lt;br /&gt;
    const int EllipseSize = 50;&lt;br /&gt;
    GraphicsState state;  // to to protect and to serve&lt;br /&gt;
&lt;br /&gt;
    // 1 - delete the old time&lt;br /&gt;
    // delete the old second hand&lt;br /&gt;
    // figure out how far around to rotate to draw the second hand&lt;br /&gt;
    // save the current state, rotate, draw and then restore the state&lt;br /&gt;
    float rotation = GetSecondRotation();&lt;br /&gt;
    state = g.Save();&lt;br /&gt;
    g.RotateTransform(rotation);&lt;br /&gt;
    g.FillEllipse(&lt;br /&gt;
      secondBrush,&lt;br /&gt;
      -(EllipseSize/2),&lt;br /&gt;
      -secondLength,&lt;br /&gt;
      EllipseSize,&lt;br /&gt;
      EllipseSize);&lt;br /&gt;
    g.Restore(state);&lt;br /&gt;
    DateTime newTime = DateTime.Now;&lt;br /&gt;
    bool newMin = false;  // has the minute changed?&lt;br /&gt;
    // if the minute has changed, set the flag&lt;br /&gt;
    if ( newTime.Minute != currentTime.Minute )&lt;br /&gt;
      newMin = true;&lt;br /&gt;
&lt;br /&gt;
    // if the minute has changed or you must draw anyway then you &lt;br /&gt;
    // must first delete the old minute and hour hand&lt;br /&gt;
    if ( newMin  || forceDraw )&lt;br /&gt;
    {&lt;br /&gt;
      // figure out how far around to rotate to draw the minute hand&lt;br /&gt;
      // save the current state, rotate, draw and then restore the state&lt;br /&gt;
      rotation = GetMinuteRotation();&lt;br /&gt;
      state = g.Save();&lt;br /&gt;
      g.RotateTransform(rotation);&lt;br /&gt;
      g.DrawLine(minutePen,0,0,0,-minuteLength);&lt;br /&gt;
      g.Restore(state);&lt;br /&gt;
      // figure out how far around to rotate to draw the hour hand&lt;br /&gt;
      // save the current state, rotate, draw and then restore the state&lt;br /&gt;
      rotation = GetHourRotation();&lt;br /&gt;
      state = g.Save();&lt;br /&gt;
      g.RotateTransform(rotation);&lt;br /&gt;
      g.DrawLine(hourPen,0,0,0,-hourLength);&lt;br /&gt;
      g.Restore(state);&lt;br /&gt;
    }&lt;br /&gt;
    // step 2 - draw the new time&lt;br /&gt;
    currentTime = newTime;&lt;br /&gt;
    hourPen.Color = Color.Red;&lt;br /&gt;
    minutePen.Color = Color.Blue;&lt;br /&gt;
    secondPen.Color = Color.Green;&lt;br /&gt;
    secondBrush = new SolidBrush(Color.Green);&lt;br /&gt;
    // draw the new second hand&lt;br /&gt;
    // figure out how far around to rotate to draw the second hand&lt;br /&gt;
    // save the current state, rotate, draw and then restore the state&lt;br /&gt;
    state = g.Save();&lt;br /&gt;
    rotation = GetSecondRotation();&lt;br /&gt;
    g.RotateTransform(rotation);&lt;br /&gt;
    g.FillEllipse(&lt;br /&gt;
      secondBrush,&lt;br /&gt;
      -(EllipseSize/2),&lt;br /&gt;
      -secondLength,&lt;br /&gt;
      EllipseSize,&lt;br /&gt;
      EllipseSize);&lt;br /&gt;
    g.Restore(state);&lt;br /&gt;
    // if the minute has changed or you must draw anyway then you &lt;br /&gt;
    // must draw the new minute and hour hand&lt;br /&gt;
    if ( newMin || forceDraw )&lt;br /&gt;
    {&lt;br /&gt;
      // figure out how far around to rotate to draw the minute hand&lt;br /&gt;
      // save the current state, rotate, draw and then restore the state&lt;br /&gt;
      state = g.Save();&lt;br /&gt;
      rotation = GetMinuteRotation();&lt;br /&gt;
      g.RotateTransform(rotation);&lt;br /&gt;
      g.DrawLine(minutePen,0,0,0,-minuteLength);&lt;br /&gt;
      g.Restore(state);&lt;br /&gt;
      // figure out how far around to rotate to draw the hour hand&lt;br /&gt;
      // save the current state, rotate, draw and then restore the state&lt;br /&gt;
      state = g.Save();&lt;br /&gt;
      rotation = GetHourRotation();&lt;br /&gt;
      g.RotateTransform(rotation);&lt;br /&gt;
      g.DrawLine(hourPen,0,0,0,-hourLength);&lt;br /&gt;
      g.Restore(state);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  // determine the rotation to draw the hour hand&lt;br /&gt;
  private float GetHourRotation()&lt;br /&gt;
  {&lt;br /&gt;
    // degrees depend on 24 vs. 12 hour clock&lt;br /&gt;
    float deg = b24Hours ? 15 : 30;&lt;br /&gt;
    float numHours = b24Hours ? 24 : 12;&lt;br /&gt;
    return( 360f * currentTime.Hour / numHours +&lt;br /&gt;
      deg * currentTime.Minute / 60f);&lt;br /&gt;
  }&lt;br /&gt;
  private float GetMinuteRotation()&lt;br /&gt;
  {&lt;br /&gt;
    return( 360f * currentTime.Minute / 60f ); &lt;br /&gt;
  }&lt;br /&gt;
  private float GetSecondRotation()&lt;br /&gt;
  {&lt;br /&gt;
    return(360f * currentTime.Second / 60f);&lt;br /&gt;
  }&lt;br /&gt;
  private static float GetSin(float degAngle)&lt;br /&gt;
  {&lt;br /&gt;
    return (float) Math.Sin(Math.PI * degAngle / 180f);&lt;br /&gt;
  }&lt;br /&gt;
  private static float GetCos(float degAngle)&lt;br /&gt;
  {&lt;br /&gt;
    return (float) Math.Cos(Math.PI * degAngle / 180f);&lt;br /&gt;
  }&lt;br /&gt;
  private void btnClockFormat_Click(object sender, System.EventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    btnClockFormat.Text = b24Hours ? &amp;quot;24 Hour&amp;quot; : &amp;quot;12 Hour&amp;quot;;&lt;br /&gt;
    b24Hours = ! b24Hours;&lt;br /&gt;
    this.Invalidate();&lt;br /&gt;
  }&lt;br /&gt;
  private void timer1_Tick(object sender, System.EventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    this.Invalidate();&lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Clock animation==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;/* Quote from &lt;br /&gt;
Programming .NET Windows Applications&lt;br /&gt;
By Jesse Liberty, Dan Hurwitz&lt;br /&gt;
First Edition October 2003 &lt;br /&gt;
Pages: 1246 (More details)&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Drawing.Drawing2D;&lt;br /&gt;
using System.Timers;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
&lt;br /&gt;
namespace Clock3CS&lt;br /&gt;
{&lt;br /&gt;
  // Rename the class&lt;br /&gt;
  public class ClockFace : System.Windows.Forms.Form&lt;br /&gt;
  {&lt;br /&gt;
    // Required designer variable.&lt;br /&gt;
    private System.ruponentModel.Container components = null;&lt;br /&gt;
  &lt;br /&gt;
    private int FaceRadius = 450;    // size of the clock face&lt;br /&gt;
    private bool b24Hours = false;    // 24 hour clock face?&lt;br /&gt;
    private System.Windows.Forms.Button btnClockFormat;    &lt;br /&gt;
    private DateTime currentTime;    // used in more than one method&lt;br /&gt;
    // new&lt;br /&gt;
    private int xCenter;        // center of the clock&lt;br /&gt;
    private int yCenter;&lt;br /&gt;
    private static int DateRadius = 600; // outer circumference for date&lt;br /&gt;
    private static int Offset = 0;    // for moving the text &lt;br /&gt;
    Font font = new Font(&amp;quot;Arial&amp;quot;, 40);  // use the same font throughout&lt;br /&gt;
    private StringDraw sdToday;      // the text to animate&lt;br /&gt;
    public ClockFace()&lt;br /&gt;
    {&lt;br /&gt;
      // Required for Windows Form Designer support&lt;br /&gt;
      InitializeComponent();&lt;br /&gt;
      // use the user&amp;quot;s choice of colors&lt;br /&gt;
      BackColor = SystemColors.Window;&lt;br /&gt;
      ForeColor = SystemColors.WindowText;&lt;br /&gt;
    &lt;br /&gt;
      // *** begin new&lt;br /&gt;
      string today = System.DateTime.Now.ToLongDateString();&lt;br /&gt;
      today = &amp;quot; &amp;quot; + today.Replace(&amp;quot;,&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
      &lt;br /&gt;
      // create a new stringdraw object with today&amp;quot;s date&lt;br /&gt;
      sdToday = new StringDraw(today,this);&lt;br /&gt;
      currentTime = DateTime.Now;&lt;br /&gt;
&lt;br /&gt;
      // set the current center based on the&lt;br /&gt;
      // client area&lt;br /&gt;
      xCenter = Width / 2;&lt;br /&gt;
      yCenter = Height / 2;&lt;br /&gt;
&lt;br /&gt;
      // *** end new&lt;br /&gt;
&lt;br /&gt;
      // update the clock by timer&lt;br /&gt;
      System.Timers.Timer timer = new System.Timers.Timer();&lt;br /&gt;
      timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimer);&lt;br /&gt;
      timer.Interval = 20;  // shorter interval - more movement&lt;br /&gt;
      timer.Enabled = true;&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
    protected override void OnPaint ( PaintEventArgs e )&lt;br /&gt;
    {&lt;br /&gt;
      base.OnPaint(e);&lt;br /&gt;
      Graphics g = e.Graphics;&lt;br /&gt;
      SetScale(g);&lt;br /&gt;
      DrawFace(g);&lt;br /&gt;
      DrawTime(g,true);  // force an update&lt;br /&gt;
    }&lt;br /&gt;
    // every time the timer event fires, update the clock&lt;br /&gt;
    public void OnTimer(Object source, ElapsedEventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
      Graphics g = this.CreateGraphics();&lt;br /&gt;
      SetScale(g);&lt;br /&gt;
      DrawFace(g);&lt;br /&gt;
      DrawTime(g,false);&lt;br /&gt;
      DrawDate(g);&lt;br /&gt;
      g.Dispose();    &lt;br /&gt;
      &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    #region Windows Form Designer generated code&lt;br /&gt;
    protected override void Dispose( bool disposing )&lt;br /&gt;
    {&lt;br /&gt;
      if( disposing )&lt;br /&gt;
      {&lt;br /&gt;
        if (components != null) &lt;br /&gt;
        {&lt;br /&gt;
          components.Dispose();&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
      base.Dispose( disposing );&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Required method for Designer support - do not modify&lt;br /&gt;
    /// the contents of this method with the code editor.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    private void InitializeComponent()&lt;br /&gt;
    {&lt;br /&gt;
      this.btnClockFormat = new System.Windows.Forms.Button();&lt;br /&gt;
      this.SuspendLayout();&lt;br /&gt;
      // &lt;br /&gt;
      // btnClockFormat&lt;br /&gt;
      // &lt;br /&gt;
      this.btnClockFormat.Location = new System.Drawing.Point(8, 8);&lt;br /&gt;
      this.btnClockFormat.Name = &amp;quot;btnClockFormat&amp;quot;;&lt;br /&gt;
      this.btnClockFormat.TabIndex = 1;&lt;br /&gt;
      this.btnClockFormat.Text = &amp;quot;24 Hours&amp;quot;;&lt;br /&gt;
      this.btnClockFormat.Click += new System.EventHandler(this.btnClockFormat_Click);&lt;br /&gt;
      // &lt;br /&gt;
      // ClockFace&lt;br /&gt;
      // &lt;br /&gt;
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
      this.ClientSize = new System.Drawing.Size(292, 266);&lt;br /&gt;
      this.Controls.AddRange(new System.Windows.Forms.Control[] {&lt;br /&gt;
                                      this.btnClockFormat});&lt;br /&gt;
      this.Name = &amp;quot;ClockFace&amp;quot;;&lt;br /&gt;
      this.Text = &amp;quot;Clock3CS&amp;quot;;&lt;br /&gt;
      this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ClockFace_MouseDown);&lt;br /&gt;
      this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
    #endregion&lt;br /&gt;
    [STAThread]&lt;br /&gt;
    static void Main() &lt;br /&gt;
    {&lt;br /&gt;
      Application.Run(new ClockFace());&lt;br /&gt;
    }&lt;br /&gt;
    private void SetScale(Graphics g)&lt;br /&gt;
    {&lt;br /&gt;
      // if the form is too small, do nothing&lt;br /&gt;
      if ( Width == 0 || Height == 0 )&lt;br /&gt;
        return;&lt;br /&gt;
      // set the origin at the center&lt;br /&gt;
      g.TranslateTransform(xCenter, yCenter);  // use the members vars&lt;br /&gt;
      // set inches to the minimum of the width &lt;br /&gt;
      // or height dividedby the dots per inch  &lt;br /&gt;
      float inches = Math.Min(Width / g.DpiX, Height / g.DpiX);&lt;br /&gt;
      // set the scale to a grid of 2000 by 2000 units&lt;br /&gt;
      g.ScaleTransform(&lt;br /&gt;
        inches * g.DpiX / 2000, inches * g.DpiY / 2000);&lt;br /&gt;
    }&lt;br /&gt;
    private void DrawFace(Graphics g)&lt;br /&gt;
    {&lt;br /&gt;
      // numbers are in forecolor except flash number in green&lt;br /&gt;
      // as the seconds go by.&lt;br /&gt;
      Brush brush = new SolidBrush(ForeColor);&lt;br /&gt;
      float x, y;&lt;br /&gt;
      // new code&lt;br /&gt;
      int numHours = b24Hours ? 24 : 12;&lt;br /&gt;
      int deg = 360 / numHours;&lt;br /&gt;
      &lt;br /&gt;
      // for each of the hours on the clock face&lt;br /&gt;
      for (int i = 1; i &amp;lt;= numHours; i++)&lt;br /&gt;
      {&lt;br /&gt;
        // i = hour  30 degrees = offset per hour  &lt;br /&gt;
        // +90 to make 12 straight up&lt;br /&gt;
        x = GetCos(i*deg + 90) * FaceRadius;&lt;br /&gt;
        y = GetSin(i*deg + 90) * FaceRadius;&lt;br /&gt;
        StringFormat format = new StringFormat();&lt;br /&gt;
        format.Alignment = StringAlignment.Center;&lt;br /&gt;
        format.LineAlignment = StringAlignment.Center;&lt;br /&gt;
        g.DrawString(&lt;br /&gt;
          i.ToString(), font, brush, -x, -y,format);&lt;br /&gt;
      &lt;br /&gt;
      }  // end for loop&lt;br /&gt;
    }    // end drawFace&lt;br /&gt;
&lt;br /&gt;
    private void DrawTime(Graphics g, bool forceDraw)&lt;br /&gt;
    {&lt;br /&gt;
      //  length of the hands&lt;br /&gt;
      float hourLength = FaceRadius * 0.5f;&lt;br /&gt;
      float minuteLength = FaceRadius * 0.7f;&lt;br /&gt;
      float secondLength = FaceRadius * 0.9f;&lt;br /&gt;
      // set to back color to erase old hands first&lt;br /&gt;
      Pen hourPen = new Pen(BackColor);&lt;br /&gt;
      Pen minutePen = new Pen(BackColor);&lt;br /&gt;
      Pen secondPen = new Pen(BackColor);&lt;br /&gt;
      // set the arrow heads&lt;br /&gt;
      hourPen.EndCap = LineCap.ArrowAnchor;&lt;br /&gt;
      minutePen.EndCap = LineCap.ArrowAnchor;&lt;br /&gt;
      // hour hand is thicker&lt;br /&gt;
      hourPen.Width = 30;&lt;br /&gt;
      minutePen.Width = 20;&lt;br /&gt;
      // second hand &lt;br /&gt;
      Brush secondBrush = new SolidBrush(BackColor);&lt;br /&gt;
      const int EllipseSize = 50;&lt;br /&gt;
      GraphicsState state;  // to to protect and to serve&lt;br /&gt;
&lt;br /&gt;
      // 1 - delete the old time&lt;br /&gt;
      // delete the old second hand&lt;br /&gt;
      // figure out how far around to rotate to draw the second hand&lt;br /&gt;
      // save the current state, rotate, draw and then restore the state&lt;br /&gt;
      float rotation = GetSecondRotation();&lt;br /&gt;
      state = g.Save();&lt;br /&gt;
      g.RotateTransform(rotation);&lt;br /&gt;
      g.FillEllipse(&lt;br /&gt;
        secondBrush,&lt;br /&gt;
        -(EllipseSize/2),&lt;br /&gt;
        -secondLength,&lt;br /&gt;
        EllipseSize,&lt;br /&gt;
        EllipseSize);&lt;br /&gt;
      g.Restore(state);&lt;br /&gt;
      DateTime newTime = DateTime.Now;&lt;br /&gt;
      bool newMin = false;  // has the minute changed?&lt;br /&gt;
      // if the minute has changed, set the flag&lt;br /&gt;
      if ( newTime.Minute != currentTime.Minute )&lt;br /&gt;
        newMin = true;&lt;br /&gt;
&lt;br /&gt;
      // if the minute has changed or you must draw anyway then you &lt;br /&gt;
      // must first delete the old minute and hour hand&lt;br /&gt;
      if ( newMin  || forceDraw )&lt;br /&gt;
      {&lt;br /&gt;
        // figure out how far around to rotate to draw the minute hand&lt;br /&gt;
        // save the current state, rotate, draw and then restore the state&lt;br /&gt;
        rotation = GetMinuteRotation();&lt;br /&gt;
        state = g.Save();&lt;br /&gt;
        g.RotateTransform(rotation);&lt;br /&gt;
        g.DrawLine(minutePen,0,0,0,-minuteLength);&lt;br /&gt;
        g.Restore(state);&lt;br /&gt;
        // figure out how far around to rotate to draw the hour hand&lt;br /&gt;
        // save the current state, rotate, draw and then restore the state&lt;br /&gt;
        rotation = GetHourRotation();&lt;br /&gt;
        state = g.Save();&lt;br /&gt;
        g.RotateTransform(rotation);&lt;br /&gt;
        g.DrawLine(hourPen,0,0,0,-hourLength);&lt;br /&gt;
        g.Restore(state);&lt;br /&gt;
      }&lt;br /&gt;
      // step 2 - draw the new time&lt;br /&gt;
      currentTime = newTime;&lt;br /&gt;
      hourPen.Color = Color.Red;&lt;br /&gt;
      minutePen.Color = Color.Blue;&lt;br /&gt;
      secondPen.Color = Color.Green;&lt;br /&gt;
      secondBrush = new SolidBrush(Color.Green);&lt;br /&gt;
      // draw the new second hand&lt;br /&gt;
      // figure out how far around to rotate to draw the second hand&lt;br /&gt;
      // save the current state, rotate, draw and then restore the state&lt;br /&gt;
      state = g.Save();&lt;br /&gt;
      rotation = GetSecondRotation();&lt;br /&gt;
      g.RotateTransform(rotation);&lt;br /&gt;
      g.FillEllipse(&lt;br /&gt;
        secondBrush,&lt;br /&gt;
        -(EllipseSize/2),&lt;br /&gt;
        -secondLength,&lt;br /&gt;
        EllipseSize,&lt;br /&gt;
        EllipseSize);&lt;br /&gt;
      g.Restore(state);&lt;br /&gt;
      // if the minute has changed or you must draw anyway then you &lt;br /&gt;
      // must draw the new minute and hour hand&lt;br /&gt;
      if ( newMin || forceDraw )&lt;br /&gt;
      {&lt;br /&gt;
        // figure out how far around to rotate to draw the minute hand&lt;br /&gt;
        // save the current state, rotate, draw and then restore the state&lt;br /&gt;
        state = g.Save();&lt;br /&gt;
        rotation = GetMinuteRotation();&lt;br /&gt;
        g.RotateTransform(rotation);&lt;br /&gt;
        g.DrawLine(minutePen,0,0,0,-minuteLength);&lt;br /&gt;
        g.Restore(state);&lt;br /&gt;
        // figure out how far around to rotate to draw the hour hand&lt;br /&gt;
        // save the current state, rotate, draw and then restore the state&lt;br /&gt;
        state = g.Save();&lt;br /&gt;
        rotation = GetHourRotation();&lt;br /&gt;
        g.RotateTransform(rotation);&lt;br /&gt;
        g.DrawLine(hourPen,0,0,0,-hourLength);&lt;br /&gt;
        g.Restore(state);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    // determine the rotation to draw the hour hand&lt;br /&gt;
    private float GetHourRotation()&lt;br /&gt;
    {&lt;br /&gt;
      // degrees depend on 24 vs. 12 hour clock&lt;br /&gt;
      float deg = b24Hours ? 15 : 30;&lt;br /&gt;
      float numHours = b24Hours ? 24 : 12;&lt;br /&gt;
      return( 360f * currentTime.Hour / numHours +&lt;br /&gt;
        deg * currentTime.Minute / 60f);&lt;br /&gt;
    }&lt;br /&gt;
    private float GetMinuteRotation()&lt;br /&gt;
    {&lt;br /&gt;
      return( 360f * currentTime.Minute / 60f ); &lt;br /&gt;
    }&lt;br /&gt;
    private float GetSecondRotation()&lt;br /&gt;
    {&lt;br /&gt;
      return(360f * currentTime.Second / 60f);&lt;br /&gt;
    }&lt;br /&gt;
    private static float GetSin(float degAngle)&lt;br /&gt;
    {&lt;br /&gt;
      return (float) Math.Sin(Math.PI * degAngle / 180f);&lt;br /&gt;
    }&lt;br /&gt;
    private static float GetCos(float degAngle)&lt;br /&gt;
    {&lt;br /&gt;
      return (float) Math.Cos(Math.PI * degAngle / 180f);&lt;br /&gt;
    }&lt;br /&gt;
    private void btnClockFormat_Click(object sender, System.EventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
      btnClockFormat.Text = b24Hours ? &amp;quot;24 Hour&amp;quot; : &amp;quot;12 Hour&amp;quot;;&lt;br /&gt;
      b24Hours = ! b24Hours;&lt;br /&gt;
      this.Invalidate();&lt;br /&gt;
    }&lt;br /&gt;
    private void DrawDate(Graphics g)&lt;br /&gt;
    {&lt;br /&gt;
      Brush brush = new SolidBrush(ForeColor);&lt;br /&gt;
      sdToday.DrawString(g,brush);&lt;br /&gt;
    }&lt;br /&gt;
    private void ClockFace_MouseDown(&lt;br /&gt;
      object sender, System.Windows.Forms.MouseEventArgs e)&lt;br /&gt;
    {&lt;br /&gt;
      xCenter = e.X;&lt;br /&gt;
      yCenter = e.Y;&lt;br /&gt;
      this.Invalidate();&lt;br /&gt;
    &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // each letter in the outer string knows how to draw itself&lt;br /&gt;
    private class LtrDraw&lt;br /&gt;
    {&lt;br /&gt;
      char myChar;    // the actual letter i draw&lt;br /&gt;
      float x;      // current x coordinate&lt;br /&gt;
      float y;      // current y coordinate&lt;br /&gt;
      float oldx;      // old x coordinate (to delete)&lt;br /&gt;
      float oldy;      // old y coordinate (to delete)&lt;br /&gt;
      &lt;br /&gt;
      // constructor&lt;br /&gt;
      public LtrDraw(char c)&lt;br /&gt;
      {&lt;br /&gt;
        myChar = c;&lt;br /&gt;
      }&lt;br /&gt;
      // property for X coordinate&lt;br /&gt;
      public float X&lt;br /&gt;
      {&lt;br /&gt;
        get { return x; }&lt;br /&gt;
        set { oldx = x; x = value; }&lt;br /&gt;
      }&lt;br /&gt;
      // property for Y coordinate&lt;br /&gt;
      public float Y&lt;br /&gt;
      {&lt;br /&gt;
        get { return y; }&lt;br /&gt;
        set { oldy = y; y = value; }&lt;br /&gt;
      }&lt;br /&gt;
      // get total width of the string&lt;br /&gt;
      public float GetWidth(Graphics g, Font font)&lt;br /&gt;
      {&lt;br /&gt;
        SizeF stringSize = g.MeasureString(myChar.ToString(),font);&lt;br /&gt;
        return stringSize.Width;&lt;br /&gt;
      }&lt;br /&gt;
      // get total height of the string&lt;br /&gt;
      public float GetHeight(Graphics g, Font font)&lt;br /&gt;
      {&lt;br /&gt;
        SizeF stringSize = g.MeasureString(myChar.ToString(),font);&lt;br /&gt;
        return stringSize.Height;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
      // get the font from the control and draw the current character&lt;br /&gt;
      // First delete the old and then draw the new&lt;br /&gt;
      public void DrawString(Graphics g, Brush brush, ClockFace cf)&lt;br /&gt;
      {&lt;br /&gt;
        Font font = cf.font;&lt;br /&gt;
        Brush blankBrush = new SolidBrush(cf.BackColor);&lt;br /&gt;
        g.DrawString(myChar.ToString(),font,blankBrush,oldx,oldy);&lt;br /&gt;
        g.DrawString(myChar.ToString(),font,brush,x,y);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    // holds an array of LtrDraw objects&lt;br /&gt;
    // and knows how to tell them to draw&lt;br /&gt;
    private class StringDraw&lt;br /&gt;
    {&lt;br /&gt;
      ArrayList theString = new ArrayList();&lt;br /&gt;
      LtrDraw l;&lt;br /&gt;
      ClockFace theControl;&lt;br /&gt;
      // constructor takes a string, populates the array&lt;br /&gt;
      // and stashes away the calling control (ClockFace)&lt;br /&gt;
      public StringDraw(string s, ClockFace theControl)&lt;br /&gt;
      {&lt;br /&gt;
        this.theControl = theControl;&lt;br /&gt;
        foreach (char c in s)&lt;br /&gt;
        {&lt;br /&gt;
          l = new LtrDraw(c);&lt;br /&gt;
          theString.Add(l);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
      // divide the circle by the number of letters&lt;br /&gt;
      // and draw each letter in position&lt;br /&gt;
      public void DrawString(Graphics g, Brush brush)&lt;br /&gt;
      {&lt;br /&gt;
        int angle = 360 / theString.Count;&lt;br /&gt;
        int counter = 0;&lt;br /&gt;
        foreach (LtrDraw theLtr in theString)&lt;br /&gt;
        {&lt;br /&gt;
          // 1. To find the X coordinate, take the Cosine of the angle&lt;br /&gt;
          // and multiply by the radius.&lt;br /&gt;
          // 2. To compute the angle, start with the base angle &lt;br /&gt;
          // (360 divided by the number of letters)&lt;br /&gt;
          // and multiply by letter position.&lt;br /&gt;
          // Thus if each letter is 10 degrees, and this is the third&lt;br /&gt;
          // letter, you get 30 degrees. Add 90 to start at 12 O&amp;quot;clock.&lt;br /&gt;
          // Each time through, subtract the clockFace offset to move &lt;br /&gt;
          // the entire string around the clock on each timer call&lt;br /&gt;
          float newX = GetCos(angle  * counter + 90 - ClockFace.Offset) * ClockFace.DateRadius ;&lt;br /&gt;
          float newY = GetSin(angle * counter + 90 - ClockFace.Offset) * ClockFace.DateRadius ;&lt;br /&gt;
          theLtr.X = &lt;br /&gt;
            newX - (theLtr.GetWidth(g,theControl.font) / 2);&lt;br /&gt;
          theLtr.Y = &lt;br /&gt;
            newY - (theLtr.GetHeight(g,theControl.font) / 2);&lt;br /&gt;
          counter++;&lt;br /&gt;
          theLtr.DrawString(g,brush,theControl);&lt;br /&gt;
        }&lt;br /&gt;
        ClockFace.Offset += 1;  // rotate the entire string&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }  // end class&lt;br /&gt;
}    // end namespace&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>