WPF 程序启动显示为通知区域的图标方法
首先需要引用 System.Windows; System.Drawing;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitialTray();
}
private System.Windows.Forms.NotifyIcon notifyIcon = null;
private void InitialTray()
{ //设置托盘的各个属性
notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.BalloonTipText = "程序开始运行";
notifyIcon.Text = "托盘图标";
notifyIcon.Icon = new System.Drawing.Icon("NotifyIcon.ico");
notifyIcon.Visible = true;
notifyIcon.ShowBalloonTip();
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick); //设置菜单项
System.Windows.Forms.MenuItem menu1 = new System.Windows.Forms.MenuItem("菜单项1");
System.Windows.Forms.MenuItem menu2 = new System.Windows.Forms.MenuItem("菜单项2");
System.Windows.Forms.MenuItem menu = new System.Windows.Forms.MenuItem("菜单", new System.Windows.Forms.MenuItem[] { menu1 , menu2 }); //退出菜单项
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("exit");
exit.Click += new EventHandler(exit_Click); //关联托盘控件
System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { menu , exit };
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen); //窗体状态改变时候触发
this.StateChanged += new EventHandler(SysTray_StateChanged);
}
/// <summary>
/// 窗体状态改变时候触发
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SysTray_StateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Minimized)
{ //this.Visibility = Visibility.Hidden;
}
} /// <summary>
/// 退出选项
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> private void exit_Click(object sender, EventArgs e)
{
if (System.Windows.MessageBox.Show("确定要关闭吗?", "退出", MessageBoxButton.YesNo,MessageBoxImage.Question,MessageBoxResult.No) == MessageBoxResult.Yes)
{
notifyIcon.Dispose();
System.Windows.Application.Current.Shutdown();
}
} /// <summary>
/// 鼠标单击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> private void notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (this.Visibility == Visibility.Visible)
{
//this.Visibility = Visibility.Hidden;
}
else
{
this.Visibility = Visibility.Visible;
this.WindowState = WindowState.Normal;
//this.Activate();
}
}
}
// 改变窗体关闭按钮事件
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;//取消窗体关闭
this.Visibility = Visibility.Hidden;//窗体隐藏
}
}
WPF 程序启动显示为通知区域的图标方法的更多相关文章
- wpf 程序启动显示图片
一.设置图片的生成操作 程序启动时会出现0.5秒的图片显示,再显示程序界面. 二.写代码实现相同效果 /// <summary> /// App.xaml 的交互逻辑 /// </s ...
- Win7通知区域的图标怎么去除?
由于本人有洁癖,最近在用win7的时候,很收不了已经卸载了的一些软件,在win7右下角的通知区域图标中还留有痕迹,于是上网查找了下解决方案. 用以下方法完美解决问题. 这里依然是以注册表的修改方法为主 ...
- 关于WPF程序启动性能
项目里WPF的启动时间太久(>1分钟),显然是不能接受的.超过10秒,连Loading的等待框都会让用户感到厌烦. 1. 症状 项目的结构是1个WPF主进程,启动3个WPF子进程.子进程在启动时 ...
- WPF 程序中启动和关闭外部.exe程序
当需要在WPF程序启动时,启动另一外部程序(.exe程序)时,可以按照下面的例子来: C#后台代码如下: using System; using System.Collections.Generic; ...
- 处理win7任务栏通知区域图标异常问题
故障现象:安装的某软件比如QQ,应用程序运行图标始终没有在win7任务栏通知区域显示出来,经观查发现win7任务栏通知区域有几个已删除应用的图标出现,应该是有故障了. 故障现象一:已经卸载的程序,还在 ...
- WPF程序在Windows 7下应用Windows 8主题
这篇博客介绍如何在Windows 7下应用Windows 8的主题. 首先我们先看一个很常见的场景,同样的WPF程序(样式未重写)在不同的操作系统上展示会有些不同.这是为什么呢?WPF程序启动时会加载 ...
- PreApplicationStartMethodAttribute程序启动扩展
一.PreApplicationStartMethodAttribute 类简介 应用程序启动时提供的扩展的支持. 命名空间: System.Web程序集: System.Web(位于 Syst ...
- WPF ListView 居中显示
原文:WPF ListView 居中显示 今天遇到的问题: 方法1:设置GridViewColumn的ActualWidth <ListView > <ListView.View&g ...
- Win10任务栏通知区域上已卸载程序无效图标选项如何清除?
在Win10系统中,大部分用户都已经知道在“选择在任务栏上显示哪些图标”来让一些软年图标显示,一些隐藏,不过使用Win10系统久了之后发现,在设置通知区域图标中有很多已经卸载程序的无效选项!这让设置时 ...
随机推荐
- JFreeChart 使用一 饼图之高级特性
原文链接:http://www.cnblogs.com/jtmjx/archive/2013/04/23/jfreechart_advantage.html 本文主要讲解JFreeChart中饼图的一 ...
- Practical JAVA (四)异常处理
Practice 16~27 一 异常控制流(exceptional control flow)机制: try{ <block> } catch(<ExceptionClass> ...
- LoadRunner脚本
Action() { char *str1=(char *)malloc(1024*sizeof(char)); char *str2="0"; char *str3=(char ...
- 启动windows的服务--《用delphi开发共享软件》-15.2桌面提示器
在dos 下用命令启动一个服务:NET START "Windows Desktop Reminder" 一下为用delphi启动服务: Function RunProcess(s ...
- Spring Integration - 自动轮询发送手机短信
Spring Integration 配置 <?xml version="1.0" encoding="UTF-8"?> <beans xml ...
- JavaScript eval() 函数
定义和用法:eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. 语法:eval(string) 参数 描述 string 必需.要计算的字符串,其中含有要计算的 Java ...
- XML Basic
XML声明: <?xml version="1.0" encoding="UTF-8"?> XML中属性的value值要被引号(单引号or双引号)引 ...
- ural 1341. Device
1341. Device Time limit: 1.0 secondMemory limit: 64 MB Major (M): You claimed that your device would ...
- ExtJs文件上传(Ext.ux.form.FileUploadField)
Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, { /** * @cfg {String} buttonText The b ...
- Mongoose简单学习笔记
1.1 名词解释 Schema : 一种以文件形式存储的数据库模型骨架,不具备数据库的操作能力 Model : 由Schema发布生成的模型,具有抽象属性和行为的数据库操作对 Entity : 由Mo ...