Cómo utilizar el lenguaje C# para crear un pequeño programa sencillo con función de cuenta regresiva.
pedir codigo
usando System;
usando System.Collections;
usando System.Timers;
usando System.Runtime.InteropServices; p>
usando System. p>
usando System.Collections.Generic;
usando System.ComponentModel;
usando System.Data;
usando System.Drawing;
p>usando System.Linq;
usando System.Text;
usando System.Windows.Forms;
temporizador de espacio de nombres
{
clase parcial pública Form1: Formulario
{
Form1 pública()
{
InitializeComponent();
}
[DllImport("kernel32",EntryPoint="Beep")]
public extern static int Beep(int dwfreq, int dwduration);
private void numericUpDown3_ValueChanged(object sender, EventArgs e)
{
cadena hora, minuto, segundo;
if (numericUpDown3.Value == 60)
{
numericUpDown3.Value = 0;
numericUpDown2.Value = Convert.ToInt32(numericUpDown2.Value) + 1;
int our = Convert.ToInt32(numericUpDown1.Value);
int niuit = Convert.ToInt32(numericUpDown2.Value);
int secon = Convert.ToInt32(numericUpDown3.Value);
if (nuestro < 10)
{
hora = "0 " + nuestro.ToString();
}
else
{
hora = nuestro.ToString();
}
if (niuit < 10)
{
minuto = "0" + niuit.ToString() + ":";
}
else
{
minuto = niuit.ToString() + ":";
}
if (segundo < 10 )
{
segundo = "0" + secon.ToString() + ":";
}
más p>
{
segundo = segundo.ToString() + ":";
}
}
más
{
int nuestro = Convert.ToInt32(numericUpDown1.Value);
int niuit = Convert.ToInt32(numericUpDown2.Value);
int secon = Convert.ToInt32(numericUpDown3.Value);
if (nuestro < 10)
{
hora = "0" + nuestro. ToString()+ ":" ;
}
else
{
hora = our.ToString()+ ":" ;
}
if (niuit < 10)
{
minuto = "0" + niuit.ToString() + " :";
}
else
{
minuto = niuit.ToString() + ":";
}
si (segundo < 10)
{
segundo = "0" + secon.ToString();
}
else
{
segundo = secon.ToString() ;
}
}
etiqueta2.Texto = hora + minuto + segundo;
}
privado void numericUpDown2_ValueChanged(remitente del objeto, EventArgs e)
{
cadena hora, minuto, segundo;
if (numericUpDown2.Value == 60)
{
numericUpDown2.Value = 0;
numericUpDown1.Value = Convert.ToInt32(numericUpDown1.Value) + 1;
int nuestro = Convert.ToInt32(numericUpDown1.Value);
int niuit = Convert.ToInt32(numericUpDown2.Value);
int secon = Convert.ToInt32(numericUpDown3.Value);
if (nuestro < 10)
{
hora = "0" + our.ToString() + ":" ;
}
else
{
hora = our.ToString() + ":" ;
}
si (niuit < 10)
{
minuto = "0" + niuit.ToString() + ":";
}
else
{
minuto = niuit.ToString() + ":";
}
if (segundo < 10)
{
segundo = "0" + secon.ToString();
}
else
{
segundo = secon.ToString() ;
}
}
else
{
int nuestro = Convert.ToInt32(numericUpDown1.Value );
int niuit = Convert.ToInt32(numericUpDown2.Value);
int secon = Convert.ToInt32(numericUpDown3.Value);
if (nuestro < 10)
{
hora = "0" + our.ToString() + ":";
}
más
{
hora = our.ToString() + ":";
}
if (niuit < 10) p>
{
minuto = "0" + niuit.ToString() + ":";
}
más
{
minuto = niuit.ToString() + ":";
}
if (segundo < 10)
{
segundo = "0" + secon.ToString() ;
}
más
{
segundo = secon.ToString();
}
}
etiqueta2.Text = hora + minuto + segundo;
}
private void numericUpDown1_ValueChanged(objeto remitente, EventArgs e)
{
cadena hora, minuto, segundo;
if (numericUpDown1.Value == 24)
{
numericUpDown1.Value = 0;
int nuestro = Convert.ToInt32(numericUpDown1.Value);
int niuit = Convert.ToInt32(numericUpDown2.Value);
int secon = Convert.ToInt32(numericUpDown3.Value);
if (nuestro < 10)
{
hora = "0" + our.ToString();
}
más
{
hora = our.ToString() ;
}
if (niuit < 10)
{
minuto = "0" + niuit.ToString() + ":";
} p>
else
{
minuto = niuit.ToString() + ":";
}
if ( segundo < 10)
{
segundo = "0" + secon.ToString() + ":";
}
else
{
segundo = segundo.ToString() + ":";
}
}
else
{
int nuestro = Convert.ToInt32(numericUpDown1.Value);
int niuit = Convert.ToInt32(numericUpDown2.Value); p> p>
int secon = Convert.ToInt32(numericUpDown3.
Valor);
if (nuestro < 10)
{
hora = "0" + our.ToString() + ":";
}
else
{
hora = our.ToString() + ":";
} p>
if (niuit < 10)
{
minuto = "0" + niuit.ToString() + ":";
}
else
{
minuto = niuit.ToString() + ":";
}
if (secon < 10)
{
segundo = "0" + secon.ToString();
}
else
{
segundo = segundo.ToString();
}
}
etiqueta2.Text = hora + minuto +segundo ;
}
botón de anulación privado1_Click(remitente del objeto, EventArgs e)
{
temporizador1.Interval = 1000 ;
timer1.Enabled = true;
}
timer1_Tick vacío privado (remitente del objeto, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
int horas = DateTime.Now.Hour;
int munit = DateTime.Now.Minute; p> p>
int segundo = DateTime.Now.Second;
long dat;
if ((int)numericUpDown1.Value &g
t; horas)
{
dat = (long)((int)numericUpDown1.Value - horas) * 3600 + ((int)numericUpDown2.Value - munit) * 60 + ((int)numericUpDown3.Value - segundo);
}
else
{
if ((int)numericUpDown2.Value > munit)
{
dat = (long)((int)numericUpDown1.Value - horas) * 3600 + ((int)numericUpDown2.Value - munit) * 60 + ( (int)numericUpDown3.Value - segundo);
}
else
{
if ((int)numericUpDown3.Value > = segundo)
{
dat = (long)((int)numericUpDown1.Value - horas) * 3600 + ((int)numericUpDown2.Value - munit) * 60 + ( (int)numericUpDown3.Value - segundo);
}
else
{
dat = (long)((int) numericUpDown1.Value + 24 - horas) * 3600 + ((int)numericUpDown2.Value - munit) * 60 + ((int)numericUpDown3.Value - segundo);
}
}
}
if (dat > 0)
{
label3.Text = "Se ha iniciado el despertador";
label4.Text = "restante" + dat.ToString() + "segundos";
}
if (dat == 0)
{
temporizador1.Enabled = false;
Pitido(200, 500);
>
label4.Text = "Ha llegado el momento";
}
}
botón de anulación privada2_Click(remitente del objeto, EventArgs e)
{
timer1.Enabled = false;
label3.Text = "La alarma se ha detenido";
}
}
}
Un programa de despertador, similar a una cuenta atrás.