Winform: clock alert
хай, как я могу сделать всплывающее окно messagebox само по себе, если время часов установлено пользователем.
пример: первые часы - 5.30 вечера
вторые часы - 5.35 вечера
если первые часы показывают 5.35 вечера, то появится окно сообщений.
Что я уже пробовал:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace SessionManager__Demo { public partial class timeCompare : Form { public timeCompare() { InitializeComponent(); timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { /******************************************* * Display Current Time *******************************************/ DateTime time1 = DateTime.Now; label1.Text = time1.ToString("hh:mm:ss:tt"); } private void button1_Click(object sender, EventArgs e) { DateTime time1 = DateTime.Now; var time2 = time1.AddHours(0).AddMinutes(0).AddSeconds(0); var t2 = time2.ToString("hh:mm:ss:tt"); label2.Text = t2; //compare time int compare = DateTime.Compare(time1, time2); if (compare == -1) { MessageBox.Show("time 1 is early"); }else if (compare == 0) { MessageBox.Show("time 1 is same with time 2"); } else { MessageBox.Show("time 1 is later"); } } } }