基本信息
源码名称:C#做的石英时钟实例源码
源码大小:0.26M
文件格式:.zip
开发语言:C#
更新时间:2013-01-16
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
石英时钟实例源码,仅供参考学习使用,效果很不错哦
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Point mouseOffset; private bool isMouseDown = false; private void clock(Graphics g) { const double pi = Math.PI; Point center = new Point(0, 0); DateTime time = DateTime.Now; //读取时间; double sec = 2.0 * pi * time.Second / 60.0; double min = 2.0 * pi * (time.Minute time.Second / 60.0) / 60.0; double hour= 2.0 * pi * (time.Hour time.Minute / 60.0) / 12.0; //各指针单位换算; int r = Math.Min(pictureBox1.Image.Width, pictureBox1.Image.Height) / 2; int secHandLength = (int)(0.55 * r); int minHandLength = (int)(0.55 * r); int hourHandLength = (int)(0.45 * r); //刷新指针; Pen SPen = new Pen(Color.White, 1); g.DrawLine(SPen, center, new Point((int)(secHandLength * Math.Sin(sec)), (int)(-secHandLength * Math.Cos(sec)))); Pen MPen = new Pen(Color.White, 2); g.DrawLine(MPen, center, new Point((int)(minHandLength * Math.Sin(min)), (int)(-minHandLength * Math.Cos(min)))); Pen HPen = new Pen(Color.White, 2); g.DrawLine(HPen, center, new Point((int)(hourHandLength * Math.Sin(hour)), (int)(-hourHandLength * Math.Cos(hour)))); } private void timer1_Tick(object sender, EventArgs e) { pictureBox1.Invalidate(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { pictureBox1.Image = (Image)Properties.Resources.bg; Image a = pictureBox1.Image; Graphics g = Graphics.FromImage(a); g.TranslateTransform(pictureBox1.Image.Width / 2, pictureBox1.Image.Height / 2, MatrixOrder.Append); clock(g); } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { int xOffset; int yOffset; if (e.Button == MouseButtons.Left) { xOffset = -e.X; yOffset = -e.Y; mouseOffset = new Point(xOffset, yOffset); isMouseDown = true; } } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (isMouseDown) { Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X, mouseOffset.Y); Location = mousePos; } } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isMouseDown = false; } } private void 前端显示ToolStripMenuItem_Click(object sender, EventArgs e) { if (前端显示ToolStripMenuItem.Checked == true) { 前端显示ToolStripMenuItem.Checked = false; this.TopMost = false; } else { 前端显示ToolStripMenuItem.Checked = true; this.TopMost = true; } } private void 隐藏时钟ToolStripMenuItem_Click(object sender, EventArgs e) { this.Hide(); } private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { this.Show(); } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } private void 显示时钟ToolStripMenuItem_Click(object sender, EventArgs e) { this.Show(); } private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e) { Application.Exit(); } private void pictureBox1_Click(object sender, EventArgs e) { } }