作者chrisQQ (ChrisLiu)
看板C_Sharp
标题Re: [问题] 如何让label 不受timer变化?
时间Fri Dec 11 23:45:44 2009
> 滑鼠移开後, 上头的数字会从 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;
+ boon stopDisplay = false;
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void button1_MouseEnter(object sender, EventArgs e)
{
+ this.stopDisplay = true;
}
private void button1_MouseLeave(object sender, EventArgs e)
{
+ this.stopDisplay = false;
}
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;
! if (!stopDisplay) Ms.Text = ms.ToString();
sec++;
! if (!stopDisplay) Sec.Text = sec.ToString();
if (sec > 59)
{
sec = 0;
! if (!stopDisplay) Sec.Text = sec.ToString();
min++;
! if (!stopDisplay) Min.Text = min.ToString();
if (min > 59)
{
min = 0;
! if (!stopDisplay) Min.Text = min.ToString();
hr++;
! if (!stopDisplay) Hr.Text = hr.ToString();
}
}
}
}
}
}
1F:→ LAGURA77:没实做 希望能帮到你@@ 12/08 22:01
我也没实做ˇˇ
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.145.202.66
2F:推 LAGURA77:这个方法好像比较简洁@@ 原po应该参考这个 12/12 19:55