mardi 6 janvier 2015

Check if the countdown timer is 0

I have a script based on the countdown timer. I want that when the time reaches 0, the timer stop and a message appear. The code id this:



public partial class simulare : Form
{
private admin admin;
Timer timer = new Timer();
public simulare(admin admin)
{
InitializeComponent();
this.admin=admin;
label2.Text = TimeSpan.FromMinutes(0.1).ToString();
}
private void simulare_Load(object sender, EventArgs e)
{
var startTime = DateTime.Now;
timer = new Timer() { Interval = 1000 };
timer.Tick += (obj, args) =>
label2.Text = (TimeSpan.FromMinutes(0.1) - (DateTime.Now - startTime)).ToString("hh\\:mm\\:ss");
timer.Enabled = true;
timer.Start();
if (condition)
{
timer.Stop();
MessageBox.Show("Done!");
}
}
}


I tried those conditions, but unsuccessful:



if (timer.ToString() == TimeSpan.Zero.ToString())

if (label2.Text.ToString() == TimeSpan.Zero.ToString())

if (label2.Text == TimeSpan.Zero)

Aucun commentaire:

Enregistrer un commentaire