Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace WinFormsApp1
- {
- public partial class Form1 : Form
- {
- System.Timers.Timer t;
- string alarmTime;
- int hours, minutes, seconds;
- public Form1()
- {
- InitializeComponent();
- //Kreiranje timer-a s periodom od 1000 ms
- t = new System.Timers.Timer(1000);
- t.Enabled = true;
- //Dodavanje događaja timer-u; izvršava se periodno
- t.Elapsed += new System.Timers.ElapsedEventHandler(checkAlarm);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- t.Enabled = true;
- hours = Int32.Parse(richTextBox1.Text);
- minutes= Int32.Parse(richTextBox2.Text);
- seconds= Int32.Parse(richTextBox3.Text);
- alarmTime=hours.ToString()+":"+minutes.ToString()+":"+seconds.ToString();
- label2.Text = alarmTime;
- }
- private void checkAlarm(object s, EventArgs e)
- {
- //Metoda Invoke izvršava delegata na niti koja je vlasnik
- //rukovatelja kontrola (uobičajeno, glavna nit)
- //MethodInvoker je delegat koji može izvršiti bilo koju
- //metodu koja ne vraća ništa i nema parametre
- Invoke((MethodInvoker)delegate //Anonimna metoda
- {
- label1.Text = DateTime.Now.ToString("HH:mm:ss");
- if (alarmTime == label1.Text)
- {
- Console.Beep();
- t.Enabled = false;
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement