C#编写的clock
来源:互联网 发布:java实现日志记录 编辑:程序博客网 时间:2024/06/07 13:40
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyClockApp
{
public partial class Clock : Form
{
public Clock()
{
InitializeComponent();
}
/// <summary>
/// 得到当前系统时间,并将其拼接成一个字符串
/// </summary>
/// <returns>数字时钟要显示的字符串</returns>
public string GetTime()
{
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;
}
/// <summary>
/// 在窗体上画表盘时钟的图形
/// </summary>
/// <param name="h"></param>
/// <param name="m"></param>
/// <param name="s"></param>
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);
}
/// <summary>
/// 定时刷新显示时间
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
/// <summary>
/// 若无此方法,时钟也能显示,但要等窗体显示几秒以后表盘才会显示。有了此方法窗体和表盘同时显示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
}
}
- C#编写的clock
- 一个C#写的CLOCK程序
- C#编写的计算器
- C#编写的记事本
- c#编写的记事本
- C#编写的通讯录
- C++ 编写延时循环 clock() CLOCKS_PER_SEC
- C#时钟控件 (C# Clock Control)
- POSIX Clock 的实现
- 简单的Vector Clock
- clock()函数的使用
- S3C6410的clock设置
- clock()的使用
- clock、GetTickCount的计时
- clock()函数的用法
- clock的创意
- clock()函数的使用
- clock子系统的总结
- 嵌入式 移植DHCPClient
- 一道算法题:找出数组中出现次数超过一半的数
- OBJ-C 深拷贝 浅拷贝
- null也可以调用方法?????
- ubuntu11.10 安装配置XAMPP
- C#编写的clock
- 今天去游泳了,感觉很爽,回来喝了一点啤酒
- Win7虚拟机安装 Mac OS X Lion 10.7.2 及 XCode 4.2.1 (iOS SDK5.0) 作开发
- 日本社交游戏郭锋:CA子公司Cygames在美国AppStore的Rage of Bahamut进入TopSells钱10位,该游戏在play上也排在前面。其日文版“神击Bahamut”在日本Moba
- QT::QFileInfo
- 使用ActivityGroup来切换Activity和Layout
- 由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值
- 黑马程序员——java学习数组的总结
- iPhone 在xcode4.2中手工添加GPX文件,指定位置