-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.Add SystemTrayService to manage shell notifyicon 2.Update Readme.md
- Loading branch information
1 parent
0ff7f59
commit 95e5aa9
Showing
37 changed files
with
1,441 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Drawing; | ||
using System.Windows.Forms; | ||
|
||
namespace WindowsTools.Services.Root | ||
{ | ||
/// <summary> | ||
/// 系统托盘菜单服务 | ||
/// </summary> | ||
public static class SystemTrayService | ||
{ | ||
private static NotifyIcon notifyIcon; | ||
|
||
public static event MouseEventHandler MouseClick; | ||
|
||
public static event MouseEventHandler MouseDoubleClick; | ||
|
||
/// <summary> | ||
/// 初始化系统托盘 | ||
/// </summary> | ||
public static void InitializeSystemTray(string content, string iconPath) | ||
{ | ||
if (notifyIcon is null) | ||
{ | ||
notifyIcon = new NotifyIcon(); | ||
notifyIcon.Text = content; | ||
notifyIcon.Icon = Icon.ExtractAssociatedIcon(iconPath); | ||
notifyIcon.Visible = true; | ||
notifyIcon.MouseClick += OnMouseClick; | ||
notifyIcon.MouseDoubleClick += OnMouseDoubleClick; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 关闭托盘菜单 | ||
/// </summary> | ||
public static void CloseSystemTray() | ||
{ | ||
if (notifyIcon is not null) | ||
{ | ||
notifyIcon.Visible = false; | ||
notifyIcon.MouseClick -= OnMouseClick; | ||
notifyIcon.Dispose(); | ||
notifyIcon = null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 处理托盘菜单鼠标点击事件 | ||
/// </summary> | ||
private static void OnMouseClick(object sender, MouseEventArgs args) | ||
{ | ||
MouseClick?.Invoke(sender, args); | ||
} | ||
|
||
/// <summary> | ||
/// 处理托盘菜单鼠标双击事件 | ||
/// </summary> | ||
private static void OnMouseDoubleClick(object sender, MouseEventArgs args) | ||
{ | ||
MouseDoubleClick?.Invoke(sender, args); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.