mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-30 17:16:52 +13:00
73 lines
No EOL
1.9 KiB
C#
73 lines
No EOL
1.9 KiB
C#
// <copyright file="AppNotifyIcon.cs" company="PlaceholderCompany">
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
// </copyright>
|
|
|
|
namespace SystemTrayMenu.UserInterface
|
|
{
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using SystemTrayMenu.Helper;
|
|
using SystemTrayMenu.Utilities;
|
|
using Timer = System.Windows.Forms.Timer;
|
|
|
|
internal class AppNotifyIcon : IDisposable
|
|
{
|
|
private readonly NotifyIcon notifyIcon = new();
|
|
|
|
public AppNotifyIcon()
|
|
{
|
|
notifyIcon.Text = "SystemTrayMenu";
|
|
notifyIcon.Icon = Config.GetAppIcon();
|
|
notifyIcon.Visible = true;
|
|
|
|
AppContextMenu contextMenus = new();
|
|
|
|
contextMenus.ClickedOpenLog += ClickedOpenLog;
|
|
void ClickedOpenLog()
|
|
{
|
|
OpenLog?.Invoke();
|
|
}
|
|
|
|
notifyIcon.ContextMenuStrip = contextMenus.Create();
|
|
notifyIcon.MouseClick += NotifyIcon_MouseClick;
|
|
void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
VerifyClick(e);
|
|
}
|
|
|
|
notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
|
|
void NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
VerifyClick(e);
|
|
}
|
|
}
|
|
|
|
public event EventHandlerEmpty Click;
|
|
|
|
public event EventHandlerEmpty OpenLog;
|
|
|
|
public void Dispose()
|
|
{
|
|
notifyIcon.Icon = null;
|
|
notifyIcon.Dispose();
|
|
}
|
|
|
|
public void LoadingStart()
|
|
{
|
|
notifyIcon.Icon = Resources.StaticResources.LoadingIcon;
|
|
}
|
|
|
|
public void LoadingStop()
|
|
{
|
|
notifyIcon.Icon = Config.GetAppIcon();
|
|
}
|
|
|
|
private void VerifyClick(MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
Click?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
} |