using
System;
using
System.ComponentModel;
using
System.Drawing;
using
System.Drawing.Drawing2D;
using
System.Windows.Forms;
namespace
WellFormed
{
///
<summary>
/// Summary
description for HandyClock.
///
</summary>
public class
HandyClock : Control
{
Timer t=new
Timer();
public
HandyClock()
{
this.Width=20;
this.Height=20;
t.Interval=1000;
t.Tick+=new
EventHandler(t_Tick);
t.Enabled=true;
}
protected
float Radians(float
f)
{
return
(float)(f/180*Math.PI);
}
protected
void DrawHand(Graphics g,float
angle, float size)
{
angle+=90;
if(angle>360)
angle-=360;
g.DrawLine(Pens.Black,
new
PointF(this.Width/2f,
this.Height/2f),
new
PointF(
this.Width/2-
(float)Math.Cos(Radians(angle))*(this.Width/3f),
this.Height/2-
(float)Math.Sin(Radians(angle))*(this.Width/3f)
)
);
}
protected
override void
OnPaint(PaintEventArgs e)
{
e.Graphics.FillEllipse(Brushes.White,0,0,this.Width,this.Height);
e.Graphics.DrawEllipse(Pens.Black,0,0,this.Width-1,this.Height-1);
float
angle=(float)(DateTime.Now.TimeOfDay.TotalSeconds*6f);
DrawHand(e.Graphics,angle,this.Width*0.4f);
angle=(float)(DateTime.Now.TimeOfDay.TotalMinutes*6f);
DrawHand(e.Graphics,angle,this.Width*0.4f);
angle=(float)(DateTime.Now.TimeOfDay.TotalHours*30f);
DrawHand(e.Graphics,angle,this.Width*0.2f);
}
protected
override void
OnSizeChanged(EventArgs e)
{
this.Width=this.Height=20;
base.OnSizeChanged
(e);
}
private
void t_Tick(object
sender, EventArgs e)
{
Refresh();
}
WellFormed.BigClock
bc;
protected
override void
OnMouseHover(EventArgs e)
{
bc=new
WellFormed.BigClock();
bc.Create();
bc.Show();
base.OnMouseHover
(e);
}
}
}