Estos son los elementos que necesitaremos en nuestro
formulario
codigo del programa;
public partial class cronometro :
Form
{
int h = 0, m = 0, s = 0;
public cronometro()
{
InitializeComponent();
}
private void
iniciar_Click(object sender, EventArgs e)
{
h
= 0;
m
= 0;
s = 0;
lh.Text = "00";
lm.Text = "00";
ls.Text = "00";
button1.Text = "detener";
button1.Enabled = true;
timer1.Enabled = true;
}
private void
button1_Click(object sender, EventArgs e)
{
if (button1.Text == "detener")
{
button1.Text = "reanudar";
timer1.Enabled = false;
}
else
{
button1.Text = "detener";
timer1.Enabled = true;
}
}
private void
timer1_Tick(object sender, EventArgs e)
{
s
= s + 1;
if (s == 60)
{
s = 0;
m = m + 1;
if (m == 60)
{
m = 0;
h++;
if (h == 24) h = 0;
}
}
ls.Text = Convert.ToString(s);
lm.Text = Convert.ToString(m);
lh.Text = Convert.ToString(h);
if(s<10) ls.Text = "0"+ls.Text;
if(m<10) lm.Text = "0"+lm.Text;
if(h<10) lh.Text = "0"+lh.Text;
}
private void button2_Click(object
sender, EventArgs e)
{
if (MessageBox.Show(" Deseas salir ", "Salir", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
MessageBox.Show("Ud decidio salir", "adios", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
this.Close();
}
else
{
MessageBox.Show("Ud decidio no salir", "...");
}
}