Reloj digital con alarma
Código:
using System;
using System.Collections.Generic;
using System.Text;
namespace rellotgeDigitalAmbAlarma
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.Yellow;
Console.Clear();
inth, m, s, x;
int alarmaH, alarmaM, alarmaS;
String alarma;
Console.WriteLine("Introdueix les hores");
h = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introdueix els minuts");
m = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introdueix els segons");
s =Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Vols possar alarma, si o no");
alarma = Convert.ToString(Console.ReadLine());
if (alarma == "si")
{
Console.Clear();
Console.WriteLine("Introdueix les hores de l'alarma");
alarmaH = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introdueix els minuts de l'alarma");
alarmaM = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introdueix els segons de l'alarma");
alarmaS = Convert.ToInt32(Console.ReadLine());
}
else
{
alarmaH = -1;
alarmaM = -1;
alarmaS = -1;
}
while (true)
{
Console.Clear();
Console.WriteLine("Son les {0}:{1}:{2}", h, m, s);
x = Environment.TickCount;
while (Environment.TickCount <= x + 1000) ;
s = s + 1;
if (alarmaH == h && alarmaM == m && alarmaS == s)
{
Console.Beep();
Console.Beep();
Console.Beep();
}
if (s == 60)
{
s = 0;
m = m + 1;
if (m == 60)
{
m = 0;
h = h + 1;
if (h == 24)
{
h = 0;
}
}
}
}
}
}
}
Crea un nuevo proyecto, en el formulario agrega un boton, un label y copia este código en la clase de tu formulario (Tu Form.cs)
*/
//Tu código en Visual C# 2010 .NET 4.0
using System;
using System.Windows.Forms;
namespaceTuNamespace //Aki el nombre de tu namespace
{
public partial class Form1 : Form
{
private Timer timer1;
public Form1()
{
InitializeComponent();
timer1 = new Timer();
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick);
}
void timer1_Tick(object sender,EventArgs e)
{
label1.Text = DateTime.Now.ToLongTimeString();
}
private void button1_Click(object sender, EventArgs e)
{
if (!timer1.Enabled)
timer1.Start();
else
timer1.Stop();
}
}
}
//Tu código en Consola
using System;
usingSystem.Threading;
class Program
{
static void Main(string[] args)
{
while (true)
{
Console.Clear();
Console.WriteLine (DateTime.Now.ToLongTimeString() );
Thread.Sleep(1000);
}
}
}
| Anuncios Google | | USB | Projects Using VB | USBボード | USB USB 2.0 | Java USB API |
|
Identificarte
Versión...
Regístrate para leer el documento completo.