using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsDowing
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Clock : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
private Point s = new Point(0,0);
private Point m = new Point(0,0);
private Point h = new Point(0,0);
private bool drop = false;
private System.Windows.Forms.Label label1;
private Point Ds = new Point(0,0);
public Clock()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Clock));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label1
//
this.label1.ForeColor = System.Drawing.Color.Blue;
this.label1.Location = new System.Drawing.Point(8, 136);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(184, 24);
this.label1.TabIndex = 0;
this.label1.Text = "http://xinxinyi.xinwen365.com/Info/Index.htm";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label1.Click += new System.EventHandler(this.label1_Click);
this.label1.MouseEnter += new System.EventHandler(this.label1_MouseEnter);
this.label1.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
//
// Clock
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
this.ClientSize = new System.Drawing.Size(202, 202);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximumSize = new System.Drawing.Size(202, 202);
this.MinimumSize = new System.Drawing.Size(202, 202);
this.Name = "Clock";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.Load += new System.EventHandler(this.Form1_Load);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Clock());
}
private void timer1_Tick(object sender, System.EventArgs e)
{
int tmpX=0,tmpY=0;
//秒
int sa = this.GetAngle(System.DateTime.Now.Second);
tmpX = Convert.ToInt32(70*Math.Cos(this.GetArc(sa)));
tmpY = Convert.ToInt32(70*Math.Sin(this.GetArc(sa)));
s.X = 100+tmpX;
s.Y = 100+tmpY;
//分
sa = this.GetAngle(System.DateTime.Now.Minute);
tmpX = Convert.ToInt32(60*Math.Cos(this.GetArc(sa)));
tmpY = Convert.ToInt32(60*Math.Sin(this.GetArc(sa)));
m.X = 100+tmpX;
m.Y = 100+tmpY;
//時
double dbA = Math.Abs(System.DateTime.Now.Hour - 12 + (System.DateTime.Now.Minute/60.0))/12.0 * 60;
sa = this.GetAngle(Convert.ToInt32(dbA));
tmpX = Convert.ToInt32(50*Math.Cos(this.GetArc(sa)));
tmpY = Convert.ToInt32(50*Math.Sin(this.GetArc(sa)));
h.X = 100+tmpX;
h.Y = 100+tmpY;
if(this.label1.Tag.ToString()=="0")
this.label1.Text = System.DateTime.Now.ToString("HH:mm:ss");
this.Refresh();
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Pen myPen = new Pen(Color.Red);
e.Graphics.DrawEllipse(myPen,s.X-1,s.Y-1,2,2);
e.Graphics.DrawEllipse(myPen,m.X-2,m.Y-2,3,3);
e.Graphics.DrawEllipse(myPen,h.X-2,h.Y-2,3,3);
myPen = new Pen(Color.Red);
e.Graphics.DrawEllipse(myPen,100-1,100-1,2,2);
myPen = new Pen(Color.Red);
e.Graphics.DrawEllipse(myPen,100-2,100-2,4,4);
myPen = new Pen(Color.AliceBlue);
e.Graphics.DrawEllipse(myPen,0,0,200,200);
myPen = new Pen(Color.GreenYellow,1);
e.Graphics.DrawLine(myPen,new Point(100,100),s);
myPen = new Pen(Color.GreenYellow,2);
e.Graphics.DrawLine(myPen,new Point(100,100),m);
myPen = new Pen(Color.GreenYellow,3);
e.Graphics.DrawLine(myPen,new Point(100,100),h);
e.Graphics.DrawString(System.DateTime.Now.ToString("hh:mm:ss"),new System.Drawing.Font("宋体",10),new SolidBrush(Color.Black),50,210);
}
private int GetAngle(int timeNum)
{
return 360 - Math.Abs((( timeNum < 15) ? timeNum - 15 : timeNum - 75 )) * 6;
}
private double GetArc(int angle)
{
return angle * 3.14159265 / 180;
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.label1.Tag = "0";
timer1_Tick(this.timer1,null);
System.Drawing.Drawing2D.GraphicsPath myGrap = new System.Drawing.Drawing2D.GraphicsPath();
myGrap.AddEllipse(new Rectangle(0,0,200,198));
this.Region = new Region(myGrap);
this.TopMost = true;
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.drop = false;
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.drop)
{
this.Left = this.Left - this.Ds.X+e.X;
this.Top = this.Top - this.Ds.Y+e.Y;
}
}
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyData == Keys.Escape)
this.Close();
}
private void label1_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start("http://xinxinyi.xinwen365.com/Info/Index.htm");
}
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.drop = true;
this.Ds.X=e.X;
this.Ds.Y=e.Y;
}
private void label1_MouseEnter(object sender, System.EventArgs e)
{
this.label1.Text = "http://xinxinyi.xinwen365.com/Info/Index.htm";
this.label1.Tag="1";
}
private void label1_MouseLeave(object sender, System.EventArgs e)
{
this.label1.Text=System.DateTime.Now.ToString("HH:mm:ss");
this.label1.Tag="0";
}
}
}