我想要倒数计时器开始滴答两个半小时。我使用调度程序计时器
尝试了这个请找到以下代码。但它没有正确更新秒数。太快了。它一次打2秒而不是1秒
private void DrawBlackout()
{
TextBlock videoText = new TextBlock();
dt = new DispatcherTimer();
dt.Interval = new TimeSpan(0,0,1); // 1 Seconds
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
void dt_Tick(object sender, EventArgs e)
{
// do something
milliseconds = milliseconds - 1000;
label.Text = getTimeText(milliseconds / 1000);
elapsed += 1000;
//Debug.WriteLine(stopwatch.ElapsedMilliseconds + "\n");
if (milliseconds <= 1000)
dt.Stop();
}
String getTimeText(long secVal)
{
String timeString = "";
int seconds = (int)(secVal % 60);
int minutes = (int)((secVal / 60) % 60);
int hours = (int)((secVal / (60 * 60)) % 60);
if (hours <= 9)
timeString = "0" + Convert.ToString(hours) + " : ";
else
timeString = Convert.ToString(hours) + " : ";
if (minutes <= 9)
timeString = timeString + "0" + Convert.ToString(minutes) + " : ";
else
timeString = timeString + Convert.ToString(minutes) + " : ";
if (seconds <= 9)
timeString = timeString + "0" + Convert.ToString(seconds) + " ";
else
timeString = timeString + Convert.ToString(seconds) + " ";
return timeString;
}
请帮助解决此问题。
答案 0 :(得分:-1)
void DisTimer_Tick(object sender, EventArgs e)
{
timeRefresh++;
if (sec > 0)
{
sec--;
}
else if (sec == 0 && min > 0)
{
sec = 59;
min--;
}
else if (sec == 0 && min == 0 && house > 0)
{
sec = 59;
min = 59;
house--;
}
txtHouse.Text = house.ToString();
txtMin.Text = min.ToString();
txtSec.Text = sec.ToString();
if (sec == 0 && min == 0 && house == 0)
{
DisTimer.Tick -= new EventHandler(DisTimer_Tick);
getBuyer();
}
else if (timeRefresh == 60)
{
getBuyer();
DisTimer.Tick -= new EventHandler(DisTimer_Tick);
}
}
我希望能帮到你!
Thongaduka(diadiem JSC)