C#:实现托盘
1、向窗体上添加如下控件:MenuStrip menuStrip1, NotifyIcon ni_frmMain,Timer timer1, ContentMenuStrip cms_notify。其中notify中包含显示、退出等。
2、实现的代码:
#region 托盘相关代码
#region 私有方法 处理窗体的 显示 隐藏 关闭(退出)
/// <summary>
/// 显示
/// </summary>
private void ShowMainForm()
{
this.Show();
this.WindowState = this.lastFormState;
this.Activate();
this.ShowInTaskbar = true; //任务栏中显示窗体图标
//this.ni_frmMain.Visible = false;//图盘中隐藏图标
}
/// <summary>
/// 隐藏
/// </summary>
private void HideMainForm()
{
this.Hide();
this.ShowInTaskbar = false; //任务栏中显示窗体图标
//this.ni_frmMain.Visible = true;//图盘中隐藏图标
}
/// <summary>
/// 关闭(退出)
/// </summary>
private void ExitMainForm()
{
if (MessageBox.Show("您确定要退出主程序吗?", "确认退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
{
this.ni_frmMain.Visible = false;
this.Close();
this.Dispose();
Application.Exit();
}
}
#endregion
#region 右键菜单处理,显示 隐藏 退出
/// <summary>
/// 显示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmi_notifyShow_Click(object sender, EventArgs e)
{
ShowMainForm();
}
/// <summary>
/// 隐藏
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmi_notifyHide_Click(object sender, EventArgs e)
{
HideMainForm();
}
/// <summary>
/// 退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmi_notifyExit_Click(object sender, EventArgs e)
{
ExitMainForm();
}
#endregion
#region 私有方法 双击托盘上图标时,显示窗体
private void ni_frmMain_DoubleClick(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
ShowMainForm();
}
else
{
this.WindowState = FormWindowState.Minimized;
HideMainForm();
}
}
#endregion
#region 点最小化按钮时,最小化到托盘
private void frmMain_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState != FormWindowState.Minimized)
{
this.ShowInTaskbar = true; //任务栏中窗体图标显示
//this.ni_frmMain.Visible = false;
this.lastFormState = this.WindowState;
}
else
{
HideMainForm();
}
}
#endregion
#region 窗体关闭时最小化到托盘
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
//e.Cancel = true;
//this.ShowInTaskbar = false; //任务栏中窗体图标消失
//this.ni_frmMain.Visible = true;
//HideTipForm();
}
#endregion
#region 图标闪烁 开启 关闭
/// <summary>
/// 开启
/// </summary>
private void StartFlicker()
{
this.timer1.Enabled = true;
this.timer1.Start();
}
/// <summary>
/// 关闭
/// </summary>
private void CloseFlicker()
{
this.timer1.Stop();
this.timer1.Enabled = false;
this.ni_frmMain.Icon = Truelore.Fare.Client.Properties.Resources.truelore0;
}
private int i = ;
private void timer1_Tick(object sender, EventArgs e)
{
if (i < )
{
this.ni_frmMain.Icon = Truelore.Fare.Client.Properties.Resources.truelore0;
i++;
return;
}
else
{
this.ni_frmMain.Icon = Truelore.Fare.Client.Properties.Resources.truelore1;
i = ;
}
}
#endregion
#endregion
C#:实现托盘的更多相关文章
- C++ 最小化到托盘
#define WM_SHOWTASK (WM_USER + 1) void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID &a ...
- delphi 实现最小化系统托盘
1.new -->application 2.在form1中加入一个tPopMenu 命名为pm1 3.uses ShellAPI; 4.定义一个常量在 const WM_TRAYMSG = W ...
- WPF-系统托盘
WPFSystemTray.cs public class WPFSystemTray { /// <summary> /// 设置系统托盘 /// </summary> // ...
- WinForm最小化到托盘以及托盘右键菜单
首先,先拖一个NotifyIcon到主窗体,然后设置NotifyIcon的图标,不然等下最小化后,都找不到那个程序了,还有那个Text也是,不写名字,就默认是NotifyIcon了..如下图: 然后双 ...
- 小菜学习Winform(七)系统托盘
前言 有些程序在关闭或最小化的时候会隐藏在系统托盘中,双击或右击会重新显示,winform实现其功能很简单,这边就简单的介绍下. 实现 在winform实现托盘使用notifyIcon控件,如果加菜单 ...
- 将 VMware 最小化到系统托盘
1, 下载 Trayconizer官网地址: http://www.whitsoftdev.com/trayconizer/下载地址: http://www.whitsoftdev.com/files ...
- C#编写WIN32系统托盘程序
基本功能概述: 程序运行后驻留系统托盘,左键呼出,右键退出.后续可加右键菜单. 注册系统案件WIN+F10,呼出程序. 重写系统消息,最小化和关闭按钮隐藏程序 using System; using ...
- VC++ 最小化到托盘、恢复
所谓的“托盘”,在Windows系统界面中,指的就是下面任务条右侧,有系统时间等等的标志的那一部分.在程序最小化或挂起时,但有不希望占据任务栏的时候,就可以把程序放到托盘区. 一.托盘编程相关函数 ...
- WP7系统托盘和应用程序栏
(一)系统托盘和应用程序栏系统托盘(1)显示系统级别的状态信息(2)Apps能隐藏和显示系统托盘Micosoft.Phone.Shell.SystemTray.IsVisible=true;应用程序栏 ...
- QQ揭秘:如何实现托盘闪动消息提醒?【低调赠送:QQ高仿版GG 4.1 最新源码】
当QQ收到好友的消息时,托盘的图标会变成好友的头像,并闪动起来,点击托盘,就会弹出与好友的聊天框,随即,托盘恢复成QQ的图标,不再闪动.当然,如果还有其它的好友的消息没有提取,托盘的图标会变成另一个好 ...
随机推荐
- pscp
http://www.physics.rutgers.edu/~matilsky/documents/pscp.htm
- oracle 常用视图和表
1.查看当前用户的基本信息 select * from user_users 2.查看当前用户的角色 select * from user_role_privs 3.查看当前用户的系统权限和表权限 s ...
- MVC4 数据验证、特性、自动属性总结
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精 最近在做自学MVC,遇到的问题很多,索性一点点总结 ...
- OC数组中文排序
-(void)sortStudentInfo { if(studentInfoArray && studentInfoArray.count > 0) { for(TWDetai ...
- 解决eclipse svn插件 的lock问题
org.tigris.subversion.javahl.ClientException: Attemptedto lock an already-locked dir异常解决方法 myeclipse ...
- Unity3d UGUI 通用Confirm确认对话框实现(Inventory Pro学习总结)
背景 曾几何时,在Winform中,使用MessageBox对话框是如此happy,后来还有人封装了可以选择各种图标和带隐藏详情的MessageBox,现在Unity3d UGui就没有了这样的好事情 ...
- IntelliJ IDEA 下的版本控制介绍
不管是个人开发或是团队开发,版本控制都是可以很好地被使用的,目前我找不到任何开发者不使用版本控制的理由.而且对于 IDE 来讲,集成版本控制的本身就是它最大的亮点之一,很多开发者也是为此而使用它. 在 ...
- c语言的基本语法
1. 二目运算符从右往左 优先级 运算符 名称或含义 使用形式 结合方向 说明 1 [] 数组下标 数组名[常量表达式] 左到右 () 圆括号 (表达式)/函数名(形参表) . 成员选择(对象 ...
- Lintcode: Rotate String
Given a string and an offset, rotate string by offset. (rotate from left to right) Example Given &qu ...
- event对象的属性
事件类型: bubbles:布尔值,表示事件是否通过DOM以冒泡形式触发. 事件发生时,反应当前环境信息的属性: button: 表示(如果有)鼠标所按下的按钮 ctrlKey: 布尔值,表示Ctrl ...