SystemTrayMenu/Business/App.cs

65 lines
2.2 KiB
C#
Raw Normal View History

2020-03-17 09:05:52 +13:00
using Microsoft.Win32;
using System;
using System.Windows.Forms;
2020-04-30 23:22:47 +12:00
using SystemTrayMenu.Business;
2020-05-06 12:39:38 +12:00
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.Helper;
using SystemTrayMenu.UserInterface;
using SystemTrayMenu.Utilities;
namespace SystemTrayMenu
{
2020-05-06 12:39:38 +12:00
internal class App : IDisposable
{
2020-04-30 23:22:47 +12:00
private readonly MenuNotifyIcon menuNotifyIcon = new MenuNotifyIcon();
2020-05-14 05:14:51 +12:00
private readonly Menus menus = new Menus();
private TaskbarForm taskbarForm = new TaskbarForm();
2020-05-06 12:39:38 +12:00
public App()
{
2020-05-06 12:39:38 +12:00
Screen screen = Screen.PrimaryScreen;
Statics.ScreenHeight = screen.Bounds.Height;
Statics.ScreenWidth = screen.Bounds.Width;
Statics.ScreenRight = screen.Bounds.Right;
Statics.TaskbarHeight = new WindowsTaskbar().Size.Height;
2020-03-17 09:05:52 +13:00
AppRestart.BeforeRestarting += Dispose;
SystemEvents.DisplaySettingsChanged += AppRestart.ByDisplaySettings;
2020-04-30 23:22:47 +12:00
menus.LoadStarted += menuNotifyIcon.LoadingStart;
menus.LoadStopped += menuNotifyIcon.LoadingStop;
menuNotifyIcon.Exit += Application.Exit;
2020-03-17 09:05:52 +13:00
menuNotifyIcon.Restart += AppRestart.ByMenuNotifyIcon;
2020-05-01 22:41:35 +12:00
menuNotifyIcon.Click += MenuNotifyIcon_Click;
2020-05-14 05:14:51 +12:00
void MenuNotifyIcon_Click()
{
menus.SwitchOpenClose(true);
}
2020-03-17 02:45:19 +13:00
menuNotifyIcon.OpenLog += Log.OpenLogFile;
2020-04-30 23:22:47 +12:00
menus.MainPreload();
taskbarForm.Deactivate += TasbkarItemDeactivated;
taskbarForm.Activated += TasbkarItemActivated;
taskbarForm.Show();
}
internal void TasbkarItemDeactivated(object sender, EventArgs e)
{
TaskbarForm taskbarForm = (TaskbarForm)sender;
taskbarForm.WindowState = FormWindowState.Minimized;
}
internal void TasbkarItemActivated(object sender, EventArgs e)
{
TaskbarForm taskbarForm = (TaskbarForm)sender;
taskbarForm.WindowState = FormWindowState.Minimized;
taskbarForm.Focus();
menus.SwitchOpenCloseByTaskbarItem();
}
public void Dispose()
{
taskbarForm.Dispose();
2020-04-30 23:22:47 +12:00
menus.Dispose();
menuNotifyIcon.Dispose();
}
}
2019-07-05 05:04:14 +12:00
}