huuzhi 发布留言 2006-5-15 20:38
Timer控件的应用??!
我在做一个小的应用程序的时候,想添加一个Timer控件来标明程序运行的时间,我和好友也没商量出结果,手头的资料也不能解决,只好拜托各位拉!
有关控件的应用我们讲 的很少,我主要想建一个计时器,帮帮忙把![em03][em03][em11]
huuzhi 发布留言 2006-5-18 17:52
没人帮俺/?唉!!伤心难过以及痛苦[em03][em06]
梦幻情缘 发布留言 2006-5-19 19:26
那就是控制一下流程就可以了,很简单的!
月夜枫华 发布留言 2006-5-20 10:14
在程序开始运行的时候先保存此时间信息,然后使用Timer控件,固定时间获取一次当前时间,然后用当前时间减去开始时间就获得了运行了多少时间了.
xxxxx52 发布留言 2006-5-20 10:35
long timeStart;
TimeSpan timeSpan;
private void timer1_Tick(object sender, System.EventArgs e)
{
long current=System.Environment.TickCount;
timeSpan=new TimeSpan (current*10*1000);
this.label1 .Text ="本计算机启动时间:"+timeSpan.ToString ();
timeSpan=new TimeSpan((current-timeStart)*10*1000);
this.label2.Text ="程序运行时间:"+timeSpan.ToString ();
string aa=Convert.ToString(DateTime.Today);//DateTime.Today.ToString() 显示的是年月日时分秒
string[] asd=aa.Split(' ');\\使它只显示年月日
this.label3.Text ="当前时间:"+asd[0];
}
private void Form1_Load(object sender, System.EventArgs e)
{
timeStart=System.Environment.TickCount;
this.timer1 .Enabled =true;
this.timer1 .Interval =1000;
}
你看看这段代码吧 或许有帮助
an163126 发布留言 2006-5-21 13:14
不错,收藏!
googleknow 发布留言 2006-5-21 18:42
不断的学习!
huuzhi 发布留言 2006-5-22 18:59
今天刚上,谢谢各位拉[em17]
阿佑 发布留言 2006-5-22 20:39
public partial class frmTime : Form
{
int count = 0;
public frmTime ()
{
InitializeComponent();
count = Environment.TickCount;
}
/// <summary>
/// 每秒将做的事情
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
//获得机器的运行时长
int current = Environment.TickCount;
int second = current / 1000 % 60;
int minute = current / (1000 * 60) % 60;
int hour = current / (1000 * 60 * 60) ;
label3.Text = string.Format("{0}:{1}:{2}",hour,minute,second);
//获得程序运行时间
int dif = count-current ;
second = dif / 1000 % 60;
minute = dif / (1000 * 60) % 60;
hour = dif / (1000 * 60 * 60);
label4.Text = string.Format("{0}:{1}:{2}", hour, minute, second);
}
huuzhi 发布留言 2006-5-23 18:55
恩这个好 不错啊!呵呵![em17]
c476169962 发布留言 2008-7-13 12:40
设置程序的运行时间
public partial class Form1 : Form
{
int count=0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1000; //这个表示时间间隔
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
int hour = count / 3600;
int mintue = (count - hour * 3600) / 60;
int second = count - hour * 3600 - mintue * 60;
label1.Text = string.Format("{0}:{1}:{2}", hour, mintue, second);
count += 1;
}
}
[ 本帖最后由 c476169962 于 2008-7-13 12:42 编辑 [/it]]
keytolove 发布留言 2008-7-13 22:13
我还是没看懂,它是如何改变系统时间的呢!`
页: [1]