本文介绍了如何在10秒后停止时钟(示例)像国际象棋时钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Stopwatch ss = new Stopwatch();
public MainWindow()
{
InitializeComponent();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
ss.Reset();
MessageBox.Show("CLICK START BUTTON", "END");
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ss.Start();
MessageBox.Show("Play Now","GO");
listBox1.Items.Add(String.Format("{0:00} : {1:00} :
{2:00}",ss.Elapsed.Hours, ss.Elapsed.Minutes, ss.Elapsed.Seconds));
DateTime m = DateTime.Now;
DateTime n = DateTime.Now.AddSeconds(10);
int l = 5;
for (int i = 0; i <= l; i++)
{
l++;
if (m == n)
{
ss.Stop();
MessageBox.Show("end time", "Change Player");
}
else
{
MessageBox.Show("Continue");
}
}
}
推荐答案
private Stopwatch blackTimer = new Stopwatch();
private Stopwatch whiteTimer = new Stopwatch();
void tDisplay_Tick(object sender, EventArgs e)
{
labBlack.Text = ((double)blackTimer.ElapsedMilliseconds / 1000.0).ToString("0.0");
labWhite.Text = ((double)whiteTimer.ElapsedMilliseconds / 1000.0).ToString("0.0");
}
然后您只需要两个简单的按钮处理程序:
Then all you need are two simple button handlers:
private void butBlack_Click(object sender, EventArgs e)
{
butBlack.Enabled = false;
whiteTimer.Stop();
blackTimer.Start();
butWhite.Enabled = true;
}
private void butWhite_Click(object sender, EventArgs e)
{
butWhite.Enabled = false;
blackTimer.Stop();
whiteTimer.Start();
butBlack.Enabled = true;
}
这篇关于如何在10秒后停止时钟(示例)像国际象棋时钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!