显示一个托盘

 1 private NotifyIcon notifyIcon = null;  //这里在窗体上没有拖拽一个NotifyIcon控件,而是在这里定义了一个变量
 2         public Form1()
 3         {
 4             InitializeComponent();
 5             InitialTray();                   //调用初始化托盘显示函数
 6         }
 7
 8         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 9         {
10             e.Cancel = true;            //通过这里可以看出,这里的关闭其实不是真正意义上的“关闭”,而是将窗体隐藏,实现一个“伪关闭”
11             this.Hide();
12         }
13
14 private void InitialTray()
15         {
16
17             this.Hide();  //隐藏主窗体
18             notifyIcon = new NotifyIcon();   //实例化一个NotifyIcon对象
19             notifyIcon.BalloonTipText = "正在运行";  //托盘图标气泡显示的内容
20             notifyIcon.Text = "ASCII码加密与解密软件";   //托盘图标显示的内容
21             string str = System.Windows.Forms.Application.StartupPath;
22             string str1 = string.Format("{0}/33.ico",str );
23
24            // notifyIcon.Icon = new System.Drawing.Icon("G:/Visual Studio 2005/图标文件/33.ico"); //注意:下面的路径可以是绝对路径、相对路径。但是需要注意的是:文件必须是一个.ico格式
25             notifyIcon.Icon = new System.Drawing.Icon(str1);
26             notifyIcon.Visible = true; //true表示在托盘区可见,false表示在托盘区不可见
27             notifyIcon.ShowBalloonTip(2000);//气泡显示的时间(单位是毫秒)
28             notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);
29             // MenuItem help = new MenuItem("帮助");//帮助选项,这里只是“有名无实”在菜单上只是显示,单击没有效果,可以参照下面的“退出菜单”实现单击事件
30             MenuItem about = new MenuItem("关于");   //关于选项
31             MenuItem exit = new MenuItem("退出");
32             exit.Click += new EventHandler(exit_Click); //退出菜单项
33             about.Click += new EventHandler(about_Click);
34             ////关联托盘控件
35             //注释的这一行与下一行的区别就是参数不同,setting这个参数是为了实现二级菜单
36             //MenuItem[] childen = new MenuItem[] { setting, help, about, exit };
37             MenuItem[] childen = new MenuItem[] { about, exit };
38             notifyIcon.ContextMenu = new ContextMenu(childen);
39             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);//窗体关闭时触发
40
41         }
42
43  private void notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
44         {
45
46             if (e.Button == MouseButtons.Left) //鼠标左键单击
47             {
48                 //如果窗体是可见的,那么鼠标左击托盘区图标后,窗体为不可见
49                 if (this.Visible == false)
50                 {
51                     this.Visible = true;
52                 }
53                 else
54                 {
55                     this.Visible = true;
56                     this.Activate();
57                 }
58             }
59         }
60
61
62         private void exit_Click(object sender, EventArgs e)
63         {
64             //退出程序
65             System.Environment.Exit(0);
66         }
时间: 2024-08-22 16:15:01

显示一个托盘的相关文章

C#winform两个或多个panel重叠布局时如何显示一个

现象:panel1和panel2或更多panel,叠放在一起,panel和panel2是同一层次的.panel1和panel2切换时只能显示一个panel,如何切换呢? 解决方法: 1.打开vs视图-其他窗口-文档大纲,看看层次关系,就可以看出最上面的panel是窗体里显示出来的.如何让panel2出现在窗体去编辑呢? 2.拖动panel2到panel1前面,即可编辑panel2

opencv 显示一个图片/播放视频

//显示图片 #include"highgui.h" int main(int argc,char **argv) { IplImage *img=NULL; char *imgname="E:/实验/image/1.jpg"; img=cvLoadImage(imgname);//cvLoadImage加载一个图片 并返回一个IplImage指针 cvNamedWindow("test",0);//创建一个叫test的窗口,窗口大小固定 cvS

QApplication::alert 如果窗口不是活动窗口,则会向窗口显示一个警告(非常好用,效果就和TeamViewer一样)

void QApplication::alert(QWidget * widget, int msec = 0)如果窗口不是活动窗口,则会向窗口显示一个警告.警报会显示msec 毫秒.如果毫秒为零,闪烁一段时间后会停止,任务栏图标会一直亮着.widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QTimer> #include <QTime> namespace Ui { clas

用Dialog显示一个列表

要求:用Dialog对话框显示一个列表,并实现其点击效果 代码: private ListView lv_list; private String deleteName; private AlertDialog.Builder builder; private Dialog dialog; private void showDialog() { /**  * 创建Dialog,参数为当前环境与样式.  */ builder = new AlertDialog.Builder(this); Vie

[Android Pro] service中显示一个dialog 或者通过windowmanage显示view

转载: http://blog.csdn.net/huxueyan521/article/details/8954844 通过windowmananger来在窗口上添加view的时候,需要设置alert参数,而且要添加alert权限 mLayoutParams = new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, LayoutParams.TYPE_SYSTEM_ALERT,

第六篇:在SOUI中用九宫格拉伸方式显示一个图片资源

SOUI的初学者刚开始可能难以搞清楚在SOUI中显示一个图片资源的流程,这里做一个简单的示范. 首先我们准备好一张图,以下图为例. 第一步,我们首先把这个图片文件复制到demo的uires目录下,新建一个目录jpg,下面只有这一个文件9.jpg 第二步,我们需要在uires.idx中引入该图片资源 <jpg> <file name="girl" path="jpg\9.jpg"/> </jpg> 我们给这个资源命名为"g

SqlSever基础 union 联合查询,厉害的并集 重复项只显示一个 两个查询结果并在一起后排序

镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 1 base code 1 use master 2 drop database helloworld 3 4 5 --创建一个数据库 6 create database helloworld 7 8 9 10 --用helloworld1这个数据库 11 use helloworld 12 13

C++ double类型转string类型后,怎么实现小数点后只显示一个数字

C++ double类型转string类型后,怎么实现小数点后只显示一个数字 #include <iostream> #include <sstream> #include <iomanip> ?? template <class T> std::string fmt(T in, int width = 0, int prec = 0) { ????std::ostringstream s; ????s << std::setw(width) &

解决:People下面选择分享可见联系人,选择多个联系人后通过短信分享,短信中只显示一个联系人

问题描述: [操作步骤]:People下导入导出中选择分享可见联系人,选择多个联系人后通过短信分享 [测试结果]:短信中只能显示一个联系人 [预期结果]:可以显示多个联系人 经过代码分析,从compose_message_activitu.xml中的ViewStub进行定位到现实联系人名片的视图: <ViewStub android:id="@+id/vcard_attachment_view_stub" android:layout="@layout/vcard_at