窗体最小化到系统托盘
2016-07-23 11:00
549 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace RichTextBoxUse
{
public
partial class
Form1 : Form
{
NotifyIcon notifyIcon =
new NotifyIcon();//创建托盘对象
Icon icon =new
Icon("exit.ico");//创建托D盘图标对象
ContextMenu notifyContextMenu =
new ContextMenu();//创建托盘菜单对象
public Form1()
{
InitializeComponent();
notifyIcon.Text = "托盘名称";//鼠标放在托盘图标上显示的文字
notifyIcon.DoubleClick += new
EventHandler(notifyIcon_DoubleClick);
notifyIcon.MouseClick += new
MouseEventHandler(notifyIcon_MouseClick);
MenuItem mi =
new MenuItem("Exit");
notifyContextMenu.MenuItems.Add(mi);
notifyIcon.ContextMenu = notifyContextMenu;
mi.Click += new
EventHandler(mi_Click);
}
private void Form1_SizeChanged(object sender,EventArgs e)
{
if (WindowState ==
FormWindowState.Minimized)
{
notifyIcon.Icon = icon;
this.ShowInTaskbar =
false;//任务栏上不显示窗体图标
notifyIcon.Visible = true;//托盘中显示托盘图标
}
}
private void notifyIcon_DoubleClick(object sender,EventArgs e)
{
if (WindowState ==
FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;//还原窗体
this.Activate();//激活窗体并给予它焦点
this.ShowInTaskbar =true;//在任务栏上显示窗体图标
notifyIcon.Visible = false;//隐藏托盘图标
}
}
private void notifyIcon_MouseClick(object sender,MouseEventArgs e)
{
if (e.Button ==
MouseButtons.Right)
{
this.notifyIcon.ContextMenu.Show(this,new
Point(e.X, e.Y));
}
}
private void mi_Click(object sender,EventArgs e)
{
notifyIcon.Visible = false;
this.Close();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace RichTextBoxUse
{
public
partial class
Form1 : Form
{
NotifyIcon notifyIcon =
new NotifyIcon();//创建托盘对象
Icon icon =new
Icon("exit.ico");//创建托D盘图标对象
ContextMenu notifyContextMenu =
new ContextMenu();//创建托盘菜单对象
public Form1()
{
InitializeComponent();
notifyIcon.Text = "托盘名称";//鼠标放在托盘图标上显示的文字
notifyIcon.DoubleClick += new
EventHandler(notifyIcon_DoubleClick);
notifyIcon.MouseClick += new
MouseEventHandler(notifyIcon_MouseClick);
MenuItem mi =
new MenuItem("Exit");
notifyContextMenu.MenuItems.Add(mi);
notifyIcon.ContextMenu = notifyContextMenu;
mi.Click += new
EventHandler(mi_Click);
}
private void Form1_SizeChanged(object sender,EventArgs e)
{
if (WindowState ==
FormWindowState.Minimized)
{
notifyIcon.Icon = icon;
this.ShowInTaskbar =
false;//任务栏上不显示窗体图标
notifyIcon.Visible = true;//托盘中显示托盘图标
}
}
private void notifyIcon_DoubleClick(object sender,EventArgs e)
{
if (WindowState ==
FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;//还原窗体
this.Activate();//激活窗体并给予它焦点
this.ShowInTaskbar =true;//在任务栏上显示窗体图标
notifyIcon.Visible = false;//隐藏托盘图标
}
}
private void notifyIcon_MouseClick(object sender,MouseEventArgs e)
{
if (e.Button ==
MouseButtons.Right)
{
this.notifyIcon.ContextMenu.Show(this,new
Point(e.X, e.Y));
}
}
private void mi_Click(object sender,EventArgs e)
{
notifyIcon.Visible = false;
this.Close();
}
}
}
相关文章推荐
- 删除链表的中间节点和a/b处的节点
- 自增锁
- C++产生随机数
- Codeforces Round #364 (Div. 2) A 水
- codeforces #364b Cells Not Under Attack
- 字符串中单词的翻转(二)
- 十进制与其他进制之间的转换
- HDU 2502 月之数
- 海量数据中找出前k大数(topk问题)
- 快速排序算法在字符串数组排序中的应用
- JS进制转
- 设计模式演练——工厂方法模式
- Php操作mysql常用函数
- 使用 collectionView 实现表头,区头,区尾
- EventBus 3.0 事件总线
- java计算两个时间相差(天、小时、分钟、秒)
- 快速幂二进制取模算法
- 58. Length of Last Wor
- 项目中有关a标签和onclick之间的执行关系
- 分布式爬虫:使用Scrapy抓取数据