Ejemplo n.º 1
0
 private void todayLabel_Click(object sender, EventArgs e)
 {
     using (TodayForm tf = new TodayForm())
     {
         tf.ShowDialog();
         loadToday();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 主循环核心。
        /// </summary>
        internal static void runCore()
        {
            //创建一个单独的线程以供消息循环。
            Thread iconThread = new Thread(new ThreadStart(iconWorker));

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            //主循环。
            while (true)
            {
                runSpe();
                lockAll();
                unlockToday();
                Today today = Today.GetToday();

                if (today.UndoneTodayReminders.Count == 1)
                {
                    DoReminder(today.UndoneTodayReminders[0]);
                }
                else if (today.UndoneTodayReminders.Count > 1)
                {
                    using (TodayForm tf = new TodayForm())
                    {
                        tf.ShowDialog();
                    }
                }

                //挂起主循环线程直到第二天。
                DateTime now      = DateTime.Now;
                DateTime tomorrow = now.AddDays(1f);
                DateTime nextDay  = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, 0, 0, 1);
                TimeSpan gap      = nextDay - now;
                Thread.Sleep(gap);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 托盘图标管理和托盘图标、UI消息循环。
        /// </summary>
        internal static void iconWorker()
        {
            Icon      = new NotifyIcon();
            Icon.Text = "FileReminder";
            Icon.Icon = FileReminder.Properties.Resources.icon;

            MenuItem todayMenu = new MenuItem("今日事项", (s, e) =>
            {
                using (TodayForm tf = new TodayForm())
                {
                    tf.ShowDialog();
                }
            });

            todayMenu.DefaultItem = true;
            MenuItem preferenceMenu = new MenuItem("设置", (s, e) =>
            {
                using (PreferenceForm pf = new PreferenceForm())
                {
                    pf.ShowDialog();
                }
            });
            MenuItem exitMenu = new MenuItem("暂时退出", (s, e) =>
            {
                FileLockerManager.UnlockAll();
                exit(0);
            });
            MenuItem uninstallMenu = new MenuItem("停止FileReminder", (s, e) =>
            {
                if (MessageBox.Show("停止吗?新的提醒将不会再显示了。", "FileReminder停止", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        RegistryKey run;
                        run = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
                        run.DeleteValue(Application.ProductName);
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message); }
                    FileLockerManager.UnlockAll();
                    exit(0);
                }
            });

            ContextMenu menu = new ContextMenu();

            menu.MenuItems.Add(todayMenu);
            menu.MenuItems.Add(preferenceMenu);
            menu.MenuItems.Add(uninstallMenu);
            menu.MenuItems.Add(exitMenu);
            Icon.ContextMenu = menu;

            Icon.DoubleClick += (s, e) =>
            {
                using (TodayForm tf = new TodayForm())
                {
                    tf.ShowDialog();
                }
            };

            Icon.Visible = true;

            Application.Run(); //执行消息循环。
        }