[問題] 如何讓label 不受timer變化?
我目前在寫一個碼表程式
當按下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
推
12/08 21:55, , 1F
12/08 21:55, 1F
→
12/08 21:56, , 2F
12/08 21:56, 2F
→
12/08 21:58, , 3F
12/08 21:58, 3F
→
12/08 21:59, , 4F
12/08 21:59, 4F
→
12/08 22:01, , 5F
12/08 22:01, 5F
→
12/18 09:18, , 6F
12/18 09:18, 6F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):