在我的表格中,我有一个按钮和一个标签,在我班上我有一个计时器,它应该以{{1}}
开头我需要帮助,因为我需要在我的表单中启动一个timer.Start();
的计时器,但是我无法启动计时器以及我应该在表单或类计时器中的已用事件?< / p>
所以当我点击我的表单中的开始按钮时,计时器应该在我的Timer.cs中启动,并且表单中的标签应该显示计时器时间
Timer.CS
button1_Click
这是我的表格
public class Timer
{
public string TimerType { get; set; }
public Timer PersonUnlimitedTimer { get; set; }
public enum TypeTimer { Unlimited, Countdown, Limited}
int timervalue;
int minute = 60;
int second = 0;
//Valor a ser alterado pelo user
int final = 1;
public Timer()
{
timervalue = final * minute;
PersonUnlimitedTimer = new Timer();
PersonUnlimitedTimer.Interval = 1000;
PersonUnlimitedTimer.Elapsed += _PersonUnlimitedTimer_Elapsed;
PersonUnlimitedTimer.Start();
}
public Timer(TypeTimer s1)
{
switch (s1)
{
case TypeTimer.Unlimited:
second++;
TimeSpan unlimited_timer = new TimeSpan(0, 0, second);
TimerTime = unlimited_timer.ToString();
break;
case TypeTimer.Countdown:
if (second != timervalue)
{
timervalue--;
TimeSpan countdown_timer = new TimeSpan(0, 0, timervalue);
TimerTime = countdown_timer.ToString();
}
else
{
PersonUnlimitedTimer.Stop();
}
break;
case TypeTimer.Limited:
if (second != timervalue)
{
second++;
TimeSpan limited_timer = new TimeSpan(0, 0, second);
TimerTime = limited_timer.ToString();
}
else
{
PersonUnlimitedTimer.Stop();
}
break;
default:
break;
}
}
public void _PersonUnlimitedTimer_Elapsed(object sender, ElapsedEventArgs e)
{
second++;
TimeSpan unlimited_timer = new TimeSpan(0, 0, second);
TimerTime = unlimited_timer.ToString();
}
}