我只想問,如果我可以用C#秒錶我想:如何使一個秒錶C#
private void button2_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
int st = 00;
int m = 00;
string stime = "00:00";
if(st == 60)
{
m++;
st = 00;
}
else
{
st++;
}
if (m == 60)
{
m = 00;
}
if(st < 10)
{
st = 0 + st;
}
if(m < 10)
{
m = 0 + m;
}
stime = m.ToString() + ":" + st.ToString();
label3.Text = stime;
}
這一點,但它並沒有奏效。我的計時器已設置,計時器的間隔爲1000毫秒。有人能幫我嗎?
您是否在代碼中初始化了間隔?它不在代碼中發佈。 – jdweng
我在Visual Studio Designer上設置了間隔 –
這僅僅是爲了學習的目的,還是爲了一個代碼項目?如果它是一個代碼項目,那麼你應該使用Stopwatch構建。如果是學習目的,我會建議看看類中的構建:https://github.com/mono/mono/blob/master/mcs/class/System/System.Diagnostics/Stopwatch.cs –