From c055f4e19341d613a51508b33943fde3a08fa191 Mon Sep 17 00:00:00 2001 From: ema Date: Wed, 24 Jul 2024 09:26:10 +0800 Subject: [PATCH] update: support theme adjustable --- NotifyIcon/NotifyIcon.cs | 2 ++ NotifyIcon/NotifyIconColors.cs | 13 +++++++++---- NotifyIcon/NotifyIconTheme.cs | 8 ++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 NotifyIcon/NotifyIconTheme.cs diff --git a/NotifyIcon/NotifyIcon.cs b/NotifyIcon/NotifyIcon.cs index baf5c49..2426594 100644 --- a/NotifyIcon/NotifyIcon.cs +++ b/NotifyIcon/NotifyIcon.cs @@ -8,6 +8,8 @@ namespace NotifyIconEx; public class NotifyIcon { + public static NotifyIconTheme Theme { get; set; } = NotifyIconTheme.System; + private readonly System.Windows.Forms.NotifyIcon notifyIcon = null!; private readonly ToolStripRenderer toolStripRenderer = null!; protected EventHandlerList Events = new(); diff --git a/NotifyIcon/NotifyIconColors.cs b/NotifyIcon/NotifyIconColors.cs index 8690760..c3bcf5f 100644 --- a/NotifyIcon/NotifyIconColors.cs +++ b/NotifyIcon/NotifyIconColors.cs @@ -4,10 +4,15 @@ namespace NotifyIconEx; internal static class NotifyIconColors { - public static Color ForeColor => ThemeListener.IsDarkMode ? ForeColorDark : ForeColorLight; - public static Color BackColor => ThemeListener.IsDarkMode ? BackColorDark : BackColorLight; - public static Color HoverBackColor => ThemeListener.IsDarkMode ? HoverBackColorDark : HoverBackColorLight; - public static Color SeparatorColor => ThemeListener.IsDarkMode ? SeparatorColorDark : SeparatorColorLight; + private static bool IsDarkMode => + NotifyIcon.Theme == NotifyIconTheme.System + ? ThemeListener.IsDarkMode + : NotifyIcon.Theme == NotifyIconTheme.Dark; + + public static Color ForeColor => IsDarkMode ? ForeColorDark : ForeColorLight; + public static Color BackColor => IsDarkMode ? BackColorDark : BackColorLight; + public static Color HoverBackColor => IsDarkMode ? HoverBackColorDark : HoverBackColorLight; + public static Color SeparatorColor => IsDarkMode ? SeparatorColorDark : SeparatorColorLight; private static Color ForeColorLight => Color.FromArgb(0x99, 0x00, 0x00, 0x00); private static Color ForeColorDark => Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF); diff --git a/NotifyIcon/NotifyIconTheme.cs b/NotifyIcon/NotifyIconTheme.cs new file mode 100644 index 0000000..3da917d --- /dev/null +++ b/NotifyIcon/NotifyIconTheme.cs @@ -0,0 +1,8 @@ +namespace NotifyIconEx; + +public enum NotifyIconTheme +{ + System, + Light, + Dark, +}