实现在一个时间范围内,lable给出一个提示信息

water87925 2010-01-09 01:14:45
用Timer控件如何实现?
设计一个计时程序,点击 Button 开始计时,用时在10秒至20秒之间Lable提示为“合格”,超过20秒提示为“不合格”,谢谢~
...全文
209 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
mendel 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 water87925 的回复:]
补充:
timer.Interval = 10; 点击 Button1(text=开始)Lable2显示秒表计时,点击Button2(text=结束),Lable2显示秒表当前用时,当用时小或等于20秒时,Lable1显示为“合格”,超过20秒显示为“不合格”
[/Quote]

如果按秒计算的话,可以把Interval设为1000
water87925 2010-01-10
  • 打赏
  • 举报
回复
补充:
timer.Interval = 10; 点击 Button1(text=开始)Lable2显示秒表计时,点击Button2(text=结束),Lable2显示秒表当前用时,当用时小或等于20秒时,Lable1显示为“合格”,超过20秒显示为“不合格”
fatpig_007 2010-01-10
  • 打赏
  • 举报
回复
学习了
water87925 2010-01-10
  • 打赏
  • 举报
回复
补充:
timer.Interval = 10; 点击 Button 开始计时,Lable2显示秒表时间,当用时小或等于20秒时Lable1显示为“合格”,超过10秒显示为“不合格”
water87925 2010-01-10
  • 打赏
  • 举报
回复
16楼确实可行,但我要显示到00:00:00:00,怎么实现?
messi_yang 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 tianliang1 的回复:]
C# codeusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Collections;using System.Data .SqlClient ;namespace WindowsFormsApplication1
{publicpartialclass Form1 : Form
{
DateTime dateStart;//定义程序开始时的时间int i=0;//定义标识量public Form1()
{
InitializeComponent();
dateStart= System.DateTime.Now;

}privatevoid button1_Click(object sender, EventArgs e)
{this.timer1.Start();this.label1.Text="";this.label2.Text="00:00:00";
}privatevoid timer1_Tick(object sender, EventArgs e)
{

DateTime temp=new DateTime ();
temp=System .DateTime .Now;string str= (temp- dateStart).ToString ().Substring (0,8);this.label2.Text= str;
i++;if (i>=600&& i<=1200)
{this.label1.Text="合格";
}elseif(i>1200 )
{this.label1.Text="不合格";
}
}privatevoid button2_Click(object sender, EventArgs e)
{this.timer1.Stop();
}

}
}
给你写了一个,逻辑上是没有问题的,你看哈修改一下必要的地方就可以了。。。而且哪个间隔就是设置的10哈,若你原来就修改了的,不要在去修改。。。
[/Quote]
可行
water87925 2010-01-10
  • 打赏
  • 举报
回复
C# codeusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Data .SqlClient ;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
DateTime dateStart;//定义程序开始时的时间
int i = 0;//定义标识量
public Form1()
{
InitializeComponent();
dateStart = System.DateTime.Now;

}

private void button1_Click(object sender, EventArgs e)
{
this.timer1.Start();
this.label1.Text = "";
this.label2.Text ="00:00:00";
}

private void timer1_Tick(object sender, EventArgs e)
{

DateTime temp=new DateTime ();
temp =System .DateTime .Now;
string str= (temp - dateStart).ToString ().Substring (0,8);
this.label2.Text = str;
i++;
if (i >= 600 && i <= 1200)
{
this.label1.Text = "合格";
}
else if(i> 1200 )
{
this.label1.Text = "不合格";
}
}

private void button2_Click(object sender, EventArgs e)
{
this.timer1.Stop();
}

}
}


给你写了一个,逻辑上是没有问题的,你看哈修改一下必要的地方就可以了。。。而且哪个间隔就是设置的10哈,若你原来就修改了的,不要在去修改。。。




非常感谢,用你的程序我已经实现了我想要的,感谢!
另:很奇怪,我每次回复内容时,这个论坛总是要我重新登录.为什么?
tianliang1 2010-01-10
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Data .SqlClient ;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
DateTime dateStart;//定义程序开始时的时间
int i = 0;//定义标识量
public Form1()
{
InitializeComponent();
dateStart = System.DateTime.Now;

}

private void button1_Click(object sender, EventArgs e)
{
this.timer1.Start();
this.label1.Text = "";
this.label2.Text ="00:00:00";
}

private void timer1_Tick(object sender, EventArgs e)
{

DateTime temp=new DateTime ();
temp =System .DateTime .Now;
string str= (temp - dateStart).ToString ().Substring (0,8);
this.label2.Text = str;
i++;
if (i >= 600 && i <= 1200)
{
this.label1.Text = "合格";
}
else if(i> 1200 )
{
this.label1.Text = "不合格";
}
}

private void button2_Click(object sender, EventArgs e)
{
this.timer1.Stop();
}

}
}

给你写了一个,逻辑上是没有问题的,你看哈修改一下必要的地方就可以了。。。而且哪个间隔就是设置的10哈,若你原来就修改了的,不要在去修改。。。
water87925 2010-01-10
  • 打赏
  • 举报
回复
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}
MyTime timeT = new MyTime();
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}

private void button2_Click(object sender, EventArgs e)
{
timeT.Clear();
label1.Text = timeT.ToUniversalString();
}

private void timer1_Tick(object sender, EventArgs e)
{
timer1.Interval = 10;
timeT.IncreasePercent();
label1.Text = timeT.ToUniversalString();

}


private void button3_Click(object sender, EventArgs e)
{
timer1.Enabled = false;

}

以上是一个计时器程序。
这段程序,运行后,“用时”就是当点击button3后,lable1显示为:00:20:00:00时,lable2就显示"不及格”,当lable1显示为:00:20:00:00之前的时间都为及格。
kensouterry 2010-01-10
  • 打赏
  • 举报
回复
当用时小或等于20秒时,Lable1显示为“合格”,超过20秒显示为“不合格”

你这个“用时”很难定义!什么用时,终止条件在哪儿?
water87925 2010-01-10
  • 打赏
  • 举报
回复
Interval = 10
mendel 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 xr396464010 的回复:]
引用 4 楼 wuyq11 的回复:
Stopwatch watch = new Stopwatch();
watch.Start();


watch.Stop();
Console.WriteLine("执行时间为:{0}秒", watch.ElapsedMilliseconds / 1000.0f);




这贴可以的, 如果是WEB的话,定义一个变量,然后判断这变量的值是行不通的,因为每次点击BUTTON的时候会被刷新掉的呀!!1
[/Quote]


你不会保存在hiddenfiled里吗?
ProjectDD 2010-01-09
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SimpleTester6.test5 {
public partial class Form1 : Form,ITest {
public Form1() {
InitializeComponent();
//
this.timer = new Timer();
this.timer.Tick += new EventHandler(timer_Tick);
this.timer.Interval = 1000;
this.mark =this.num= 0;
}
int mark,num;
void timer_Tick(object sender,EventArgs e) {
if (this.num > this.mark) {
this.timer.Stop();
if(this.num>=10&&num<20)
MessageBox.Show("合格.");
else
MessageBox.Show("不合格.");
}
this.button1.Invoke(Delegate.CreateDelegate(typeof(Action),this,"showtimervalue"));
this.num++;
}
void showtimervalue() {
this.label1.Text = this.num.ToString();
}

Timer timer;
private void button1_Click(object sender,EventArgs e) {
this.mark = new Random().Next(1,30);
this.num = 0;
this.timer.Start();
}
}
}
xr396464010 2010-01-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]
Stopwatch watch = new Stopwatch();
watch.Start();


watch.Stop();
Console.WriteLine("执行时间为:{0}秒", watch.ElapsedMilliseconds / 1000.0f);


[/Quote]

这贴可以的, 如果是WEB的话,定义一个变量,然后判断这变量的值是行不通的,因为每次点击BUTTON的时候会被刷新掉的呀!!1
SQL77 2010-01-09
  • 打赏
  • 举报
回复
TIMER类应该可以
wuyq11 2010-01-09
  • 打赏
  • 举报
回复
Stopwatch watch = new Stopwatch();
watch.Start();


watch.Stop();
Console.WriteLine("执行时间为:{0}秒", watch.ElapsedMilliseconds / 1000.0f);

qlzf11140820 2010-01-09
  • 打赏
  • 举报
回复

int delay=0;
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1000;
timer1.Start();
delay = 15;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (delay > 0)
{
delay--;
label1.Text = "合格";
}
else {
label1.Text = "不合格";
}
}
liherun 2010-01-09
  • 打赏
  • 举报
回复
private void timer1_Tick(object sender, EventArgs e)
{
if (flag >= 10 && flag <= 20)
{
label1.Text = "合格";
}
else
{
label1.Text = "不合格";
}
flag++;
}
private int flag;
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
flag = 0;
}
liherun 2010-01-09
  • 打赏
  • 举报
回复
winform的?

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧