[問題] 如何讓label 不受timer變化?

看板C_Sharp作者 (Lizst)時間16年前 (2009/12/08 08:34), 編輯推噓1(105)
留言6則, 2人參與, 最新討論串1/2 (看更多)
我目前在寫一個碼表程式 當按下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
另外設定一個timer interval設1000 傳秒分時的工作給它做
12/08 21:55, 1F

12/08 21:56, , 2F
原來的timer作秒時分的計算就夠了
12/08 21:56, 2F

12/08 21:58, , 3F
然後假設新的TIMER叫TIMER2 buttonclick 2個timer都跑
12/08 21:58, 3F

12/08 21:59, , 4F
然後mouseenter會關掉timer2 mouseleave再打開
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
文章代碼(AID): #1B7PyRiw (C_Sharp)
文章代碼(AID): #1B7PyRiw (C_Sharp)