您好,欢迎光临本网站![请登录][注册会员]  
文件名称: c#漂亮的小时钟程序
  所属分类: C#
  开发工具:
  文件大小: 14kb
  下载次数: 0
  上传时间: 2011-01-16
  提 供 者: ericf******
 详细说明: 比较实用的c#小程序,小时钟 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; //download by http://www.codefans.net namespace MyClockApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } /// /// 得到当前系统时间,并将其拼接成一个字符串 /// /// 数字时钟要显示的字符串 public string Get Time() { String TimeInString = ""; int hour = DateTime.Now.Hour; int min = DateTime.Now.Minute; int sec = DateTime.Now.Second; //将时,分,秒连成一个字符串 TimeInString = (hour < 10) ? "0" + hour.ToString() : hour.ToString(); TimeInString += ":" + ((min < 10) ? "0" + min.ToString() : min.ToString()); TimeInString += ":" + ((sec < 10) ? "0" + sec.ToString() : sec.ToString()); return TimeInString; } /// /// 在窗体上画表盘时钟的图形 /// /// /// /// private void MyDrawClock(int h, int m, int s) { Graphics g = this.CreateGraphics(); Rectangle rect = this.ClientRectangle; g.Clear(Color.White); Pen myPen = new Pen(Color.Black, 1); g.DrawEllipse(myPen, this.ClientRectangle.Width / 2 - 75, this.ClientRectangle.Height / 2-75, 150, 150);//画表盘 Point centerPoint = new Point(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2);//表的中心点 //计算出秒针,时针,分针的另外一个商点 Point secPoint = new Point((int)(centerPoint.X + (Math.Sin(s * Math.PI / 30) * 50)), (int)(centerPoint.Y - (Math.Cos(s * Math.PI / 30) * 50))); Point minPoint = new Point((int)(centerPoint.X + (Math.Sin(m * Math.PI / 30) * 40)), (int)(centerPoint.Y - (Math.Cos(m * Math.PI / 30) * 40))); Point hourPoint = new Point((int)(centerPoint.X + (Math.Sin(h * Math.PI / 6) * 30) - m * Math.PI / 360), (int)(centerPoint.Y - (Math.Cos(h * Math.PI / 6) * 30) - m * Math.PI / 360)); //以不同颜色和宽度绘制表针 myPen = new Pen(Color.Red, 1); g.DrawLine(myPen, centerPoint, secPoint); myPen = new Pen(Color.Green, 2); g.DrawLine(myPen, centerPoint, minPoint); myPen = new Pen(Color.Orange, 4); g.DrawLine(myPen, centerPoint, hourPoint); } /// /// 定时刷新显示时间 /// /// /// private void timer1_Tick(object sender, EventArgs e) { int h = DateTime.Now.Hour; int s = DateTime.Now.Second; int m = DateTime.Now.Minute; MyDrawClock(h, m, s); toolStripStatusLabel1.Text = string.Format("{0}:{1}:{2}", h, m, s); lblTime.Text = GetTime(); } /// /// 若无此方法,时钟也能显示,但要等窗体显示几秒以后表盘才会显示。有了此方法窗体和表盘同时显示 /// /// /// private void Form1_Paint(object sender, PaintEventArgs e) { int h = DateTime.Now.Hour; int s = DateTime.Now.Second; int m = DateTime.Now.Minute; MyDrawClock(h, m, s); toolStripStatusLabel1.Text = string.Format("{0}:{1}:{2}", h, m, s); lblTime.Text = GetTime(); } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: c#
 输入关键字,在本站1000多万海量源码库中尽情搜索: