作者Lizstlin (Lizst)
看板C_Sharp
标题[问题] 如何让label 不受timer变化?
时间Tue Dec 8 08:34:32 2009
我目前在写一个码表程式
当按下button1 的时候就开始执行
可是现在有个小问题, 我想让滑鼠移入button1 的时候
label 上头的数字会静止, 但是timer继续跑
滑鼠移开button1 的时候, label 上的数字继续变化
比方说: (这是显示的格式 小时:分钟:秒:十分之一秒)
按下开始後, 过一段时间, 目前显示 00:00:31:2
假设我滑鼠在button1上头停了 3/10秒
滑鼠移开後, 上头的数字会从 00:00:31:5 继续跑
想请教各位这功能应该怎麽加入? 谢谢
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int ms, sec, min, hr;
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void button1_MouseEnter(object sender, EventArgs e)
{
}
private void button1_MouseLeave(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
Ms.Text = "00";
Sec.Text = "00";
Min.Text = "00";
Hr.Text = "00";
}
private void timer1_Tick(object sender, EventArgs e)
{
ms++;
Ms.Text = ms.ToString();
if (ms > 9)
{
ms = 0;
Ms.Text = ms.ToString();
sec++;
Sec.Text = sec.ToString();
if (sec > 59)
{
sec = 0;
Sec.Text = sec.ToString();
min++;
Min.Text = min.ToString();
if (min > 59)
{
min = 0;
Min.Text = min.ToString();
hr++;
Hr.Text = hr.ToString();
}
}
}
}
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.115.202.53
1F:推 LAGURA77:另外设定一个timer interval设1000 传秒分时的工作给它做 12/08 21:55
2F:→ LAGURA77:原来的timer作秒时分的计算就够了 12/08 21:56
3F:→ LAGURA77:然後假设新的TIMER叫TIMER2 buttonclick 2个timer都跑 12/08 21:58
4F:→ LAGURA77:然後mouseenter会关掉timer2 mouseleave再打开 12/08 21:59
5F:→ LAGURA77:没实做 希望能帮到你@@ 12/08 22:01
6F:→ Lizstlin:恩, 了解了^^ 谢谢 12/18 09:18