计时精度到底毫秒级别或者更高 如何使用C#制作一个精确计时器
2008-10-20 09:13
756 查看
代码如下:Private Declare Function GetTickCount Lib "kernel32" () As Long Public SStart EventArgs e) { time.IsInc = true; time.IsDec = false; } private void decrease_btn_Click(object sender EventArgs e) { if (time.IsInc) time.incease(); else { time.decrease(); } label1.Text = time.Hour.ToString() + ":" + time.Minute.ToString() + ":" + time.Second.ToString(); } private void increase_btn_Click(object sender EventArgs e) { //this.getList(); time = new TIME(); time.Second = int.Parse(System.DateTime.Now.Second.ToString()); time.Minute = int.Parse(System.DateTime.Now.Minute.ToString()); time.Hour = int.Parse(System.DateTime.Now.Hour.ToString()); } private void timer1_Tick(object sender
写一个TIME类 代码: class TIME { private int hour; private int minute; private int second; private bool isInc; private bool isDec; public int Hour { get { return this.hour; } set { this.hour = value; } } public int Minute { get { return this.minute; } set { this.minute = value; } } public int Second { get { return this.second; } set { this.second = value; } } public bool IsInc { get { return this.isInc; } set { this.isInc = value; } } public bool IsDec { get { return this.isDec; } set { this.isDec = value; } } public void incease() { if (this.Second < 60) this.Second++; else { if (this.minute < 60) this.minute++; else { this.hour++; } } } public void decrease() { if (this.Second > 0) this.Second--; else { if (this.minute > 0) this.minute--; else { this.minute = 59; this.hour--; } } } }主窗体中的代码: TIME time; private void Form1_Load(object sender Stime Private Sub Command1_Click() Command1.Enabled = False: Command2.Enabled = True: Command2.Default = True SStart = GetTickCount Text1.Text = Text1.Text & "你点击[开始]的时间:" & Now & vbCrLf End Sub Private Sub Command2_Click() SEnd = GetTickCount Stime = Val(SEnd - SStart) Text1.Text = Text1.Text & "你点击[停止]的时间:" & Now & vbCrLf & "已经过时间:" & Stime / 1000 & "秒" & Stime Mod 1000 & "毫秒" & vbCrLf End Sub Private Sub Form_Load() Command1.Caption = "开始": Command2.Caption = "停止": Command2.Enabled = False: Text1.Text = "": Command1.Default = True End Sub
|||
ytu77u
SEnd EventArgs e) { time.IsDec = true; time.IsInc = false; }这个实现的是现在以秒为单位的倒计时 你可以根据需要调节TIME的INTERVAL属性来实现你需要的功能
|||
终于写完了
写一个TIME类 代码: class TIME { private int hour; private int minute; private int second; private bool isInc; private bool isDec; public int Hour { get { return this.hour; } set { this.hour = value; } } public int Minute { get { return this.minute; } set { this.minute = value; } } public int Second { get { return this.second; } set { this.second = value; } } public bool IsInc { get { return this.isInc; } set { this.isInc = value; } } public bool IsDec { get { return this.isDec; } set { this.isDec = value; } } public void incease() { if (this.Second < 60) this.Second++; else { if (this.minute < 60) this.minute++; else { this.hour++; } } } public void decrease() { if (this.Second > 0) this.Second--; else { if (this.minute > 0) this.minute--; else { this.minute = 59; this.hour--; } } } }主窗体中的代码: TIME time; private void Form1_Load(object sender Stime Private Sub Command1_Click() Command1.Enabled = False: Command2.Enabled = True: Command2.Default = True SStart = GetTickCount Text1.Text = Text1.Text & "你点击[开始]的时间:" & Now & vbCrLf End Sub Private Sub Command2_Click() SEnd = GetTickCount Stime = Val(SEnd - SStart) Text1.Text = Text1.Text & "你点击[停止]的时间:" & Now & vbCrLf & "已经过时间:" & Stime / 1000 & "秒" & Stime Mod 1000 & "毫秒" & vbCrLf End Sub Private Sub Form_Load() Command1.Caption = "开始": Command2.Caption = "停止": Command2.Enabled = False: Text1.Text = "": Command1.Default = True End Sub
|||
ytu77u
SEnd EventArgs e) { time.IsDec = true; time.IsInc = false; }这个实现的是现在以秒为单位的倒计时 你可以根据需要调节TIME的INTERVAL属性来实现你需要的功能
|||
终于写完了
相关文章推荐
- C#如何使用webbrowser控件制作一个简易的IE浏览器(菜鸟级)
- 由如何设置精确到毫秒级别计时器带来的探索
- 如何使用 AllowPartiallyTrustedCallers 属性来调用具有一个强名称从 Web 页通过使用 Visual C#.NET、 Visual C# 2005年或更高版本的程序集
- 本文教你如何使用autoconf、automake等来制作一个以源代码形式(.tar.gz)发布的软件、并可在执行configure时使用自定义参数。
- 求一个C++或Java或者C#写的支持C89的编译器前端,如何解析C语言的声明?
- 如何用c#来制作一个activeX控件或类似的东西
- C# 如何让 多线程中每个线程间隔毫秒执行同一个方法
- 建立一个更高级别的查询 API:正确使用Django ORM 的方式
- 使用C#编写一个计时器(原创)
- (译)如何使用cocos2d和box2d来制作一个Breakout游戏:第一部分
- 使用Quartz.net、Topshelf、wcf命名管道制作的一个c#定时任务管理程序(热插拔)
- eclipse 中main()函数中的String[] args如何使用?通过String[] args验证账号密码的登录类?静态的主方法怎样才能调用非static的方法——通过生成对象?在类中制作一个方法——能够修改对象的属性值?
- (译)如何使用GameCenter制作一个简单的多人游戏教程:第一部分
- (译)如何使用GameCenter制作一个简单的多人游戏教程:第二部分
- (译)如何使用cocos2d制作一个太空射击游戏
- 如何使用cocos2d-x来制作一个塔防游戏:第二部分
- (译)如何使用cocos2d制作一个打地鼠的游戏:(第二部分。完)
- C# format 日期 各种 符号 实例分析如何精确C#日期格式到毫秒
- 使用工具制作覆盖图切片时,如何确定源图级别
- (译)如何使用GameCenter制作一个简单的多人游戏教程:第一部分