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的图标,不再闪动.当然,如果还有其它的好友的消息没有提取,托盘的图标会变成另一个好 ...
随机推荐
- IDE硬盘 SCSI硬盘 SATA硬盘
IDE一般是有扁平电缆连接的,一个扁平电缆可以连接2个IDE硬盘,而一个计算机一般提供2个扁平电缆,所以一般允许4块IDE硬盘.IDE经过多年的发展,成熟,廉价,稳定.一般老式的电脑中装的都是这种硬盘 ...
- pscp
http://www.physics.rutgers.edu/~matilsky/documents/pscp.htm
- 获取Json数据某节点的值
时间匆忙,直接上代码,回家还得做清蒸鱼呢! #region 获取Json字符串某节点的值 /// <summary> /// 获取Json字符串某节点的值 /// </summary ...
- 数据库报ORA-00600: 内部错误代码, 参数: [17059],并产生大量trace日志文件
用户反馈数据库服务器磁盘空间使用耗尽. 登录服务器后查看,发现数据库产生大量的trace日志,并在alert日志中发现ora-600错误 alert日志信息: Fri Jul :: Errors ): ...
- linux:centos准备及安装
1>.安装前准备(将虚拟机和映像文件iso下载好) 1.1>.centos下载(建议使用Filezilla下载(http://filezilla-project.org/download. ...
- HUD 5086 Revenge of Segment Tree(递推)
http://acm.hdu.edu.cn/showproblem.php?pid=5086 题目大意: 给定一个序列,求这个序列的子序列的和,再求所有子序列总和,这些子序列是连续的.去题目给的第二组 ...
- 父类构造函数中的this指针在子类构造对象后,这个this指针指向什么
子类的对象内存布局包括两部分:父类和子类派生部分,所以执行父类的构造函数只不过是在构造子类对象的父类部分.因此子类对象的this指针是指向子类对象自己.
- 手动写的第一个eChart代码
手动写的第一个eChart代码 ,第一感觉,杂乱无章 <!doctype html> <html> <head> <meta charset="UT ...
- em和rem及rem在移动的应用
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style t ...
- css3实现条纹背景
<!DOCTYPE HTML><html><head><meta charset='utf-8'/><meta forua="true& ...