Advertisement
blajbaca

RSSV_LV1_Z2

Mar 14th, 2023 (edited)
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. namespace WinFormsApp1
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         System.Timers.Timer t;
  6.         string alarmTime;
  7.         int hours, minutes, seconds;
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.             //Kreiranje timer-a s periodom od 1000 ms
  12.             t = new System.Timers.Timer(1000);
  13.             t.Enabled = true;
  14.             //Dodavanje događaja timer-u; izvršava se periodno
  15.             t.Elapsed += new System.Timers.ElapsedEventHandler(checkAlarm);
  16.         }
  17.  
  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             t.Enabled = true;
  21.             hours = Int32.Parse(richTextBox1.Text);
  22.             minutes= Int32.Parse(richTextBox2.Text);
  23.             seconds= Int32.Parse(richTextBox3.Text);
  24.             alarmTime=hours.ToString()+":"+minutes.ToString()+":"+seconds.ToString();
  25.             label2.Text = alarmTime;
  26.         }
  27.         private void checkAlarm(object s, EventArgs e)
  28.         {
  29.             //Metoda Invoke izvršava delegata na niti koja je vlasnik
  30.             //rukovatelja kontrola (uobičajeno, glavna nit)
  31.             //MethodInvoker je delegat koji može izvršiti bilo koju
  32.             //metodu koja ne vraća ništa i nema parametre
  33.             Invoke((MethodInvoker)delegate //Anonimna metoda
  34.             {
  35.                 label1.Text = DateTime.Now.ToString("HH:mm:ss");
  36.                 if (alarmTime == label1.Text)
  37.                 {
  38.                     Console.Beep();
  39.                     t.Enabled = false;
  40.                 }
  41.             });
  42.         }
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement