程序添加托盘图标
UI层
csharp
//添加handycontrol的引用
xmlns:hc="https://handyorg.github.io/handycontrol"
//添加NotifyIcon图标 实现单击 双击 二级菜单点击功能
<hc:NotifyIcon
Text="通知"
Token="Info">
<hc:NotifyIcon.ContextMenu>
<ContextMenu>
<MenuItem Command="hc:ControlCommands.PushMainWindow2Top" Header="Open" />
<MenuItem Command="hc:ControlCommands.ShutdownApp" Header="Exit" />
</ContextMenu>
</hc:NotifyIcon.ContextMenu>
<hc:Interaction.Triggers>
<hc:EventTrigger EventName="Click">
<hc:EventToCommand Command="hc:ControlCommands.PushMainWindow2Top"/>
</hc:EventTrigger>
<hc:EventTrigger EventName="MouseDoubleClick">
<hc:EventToCommand Command="hc:ControlCommands.PushMainWindow2Top"/>
</hc:EventTrigger>
</hc:Interaction.Triggers>
</hc:NotifyIcon>
后台调用,通过设置的Token值获取到NotifyIcon实例,显示图标
csharp
private void SendNotification()
{
NotifyIcon.ShowBalloonTip("托盘图标测试", "托盘", NotifyIconInfoType.None,"Info");
}
当窗口关闭时,提示
csharp
//是否启用托盘图标显示功能
private bool UseMode=true;
protected override void OnClosing(CancelEventArgs e)
{
if(UseMode)
{
HandyControl.Controls.MessageBox.Info(Properties.Settings.Default.关闭软件提示, "提示");
Hide();
e.Cancel = true;
}
else
{
base.OnClosing(e);
}
}
Properties.Settings.Default.XXX :读取配置文件Settings.settings中的值
HandyControl.Controls.MessageBox.Info:HandyControl窗口提示信息