惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
The Cloudflare Blog
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
F
Fortinet All Blogs
J
Java Code Geeks
人人都是产品经理
人人都是产品经理
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
爱范儿
爱范儿
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
小众软件
小众软件
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队

博客园 - 太白飞仙

.Net网络资源 CI创意的方法与技巧 可控人生核聚变 用c#备份和还原sql server 2000数据库 论文先睹:关于科学的生命哲学的思考 蚂蚁造山的思考 语言争霸VS魔兽争霸 :: IT世界VS魔兽世界 第九章 SQL Server的简单应用 [导入]文章藏金阁 [导入]敏捷实验室的一次争论 [导入]Netron研究(四)----"移动和联通"之联通篇 [导入]Netron研究(二)----"容器"登场 [导入]Netron研究(一)----初识 [导入]Netron研究(三)----"移动和联通"之移动篇 [导入]Agile Framework的日志服务 [导入]Agile Framework工作流服务的设计思路 [导入]KISS原则 [导入]WWF工作流引擎的一个奇怪现象 - 太白飞仙 - 博客园 [导入]时刻提防过度设计
[导入]类型MSN窗体行为的实现(.NET 2.0) - 太白飞仙 - 博客园
太白飞仙 · 2006-01-16 · via 博客园 - 太白飞仙

    当我们点击MSN窗体的"X"关闭程序时,MSN并不退出,而是最小化窗体,并且不在任务栏上显示.托盘区显示该程序.现在,我用VS2005实现类似的效果.
    .NET 2.0的窗体中多了一个"ShowInTaskbar"的属性,指示该应用程序是否显示在任务栏.有了这个属性,我们的实现就简单多了.
    首先,把窗体的ShowInTaskbar属性设为False,然后添加一个NotifyIcon控件,一个Menu控件,一个ContextMenu控件(用于和NotifyIcon关联).Menu和ContextMenu都只添加一个"Exit"菜单项,来控制窗体的行为.
    部分代码如下:

    窗体关闭事件代码

private void Form1_FormClosing(object sender, FormClosingEventArgs e) { //窗体关闭事件 if (this.WindowState != FormWindowState.Minimized) { e.Cancel = true; this.WindowState = FormWindowState.Minimized; this.notifyIcon1.ShowBalloonTip(3000, "My App",

               "My App is not closed.\n it's minimized!", ToolTipIcon.Info); } }

    双击托盘区图标时间代码

private void notifyIcon1_DoubleClick(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.ShowInTaskbar = true; //重新显示窗口 this.Show(); this.WindowState = FormWindowState.Normal; } this.Activate();//激活窗口 this.Focus(); }

    点击Menu和ContextMenu的"Exit"菜单项事件

private void exitToolStripMenuItem_Click(object sender, EventArgs e) { //点击菜单中的"Exit"事件 this.WindowState = FormWindowState.Minimized; Close(); } private void exitToolStripMenuItem1_Click(object sender, EventArgs e) { //点击ContextMenu中的"Exit"事件 this.WindowState = FormWindowState.Minimized; Close(); }

----2005.12.15 10:26 星期四
文章来源:http://www.agilelabs.cn/blogs/woody/archive/2005/12/15/257.aspx