由于自己在写一个小的C#程序,在程序中需要使用到系统托盘的功能。
在网上找了很多都是这样的:
private void Form1_SizeChanged(object sender, System.EventArgs e) { NotifyIcon组件 if(this.WindowState==System.Windows.Forms.FormWindowState.Minimized) { this.Hide(); this.notifyIcon1.Visible=true; } } private void notifyIcon1_Click(object sender, System.EventArgs e) { if(this.WindowState==System.Windows.Forms.FormWindowState.Minimized) { this.Visible=true; this.WindowState=System.Windows.Forms.FormWindowState.Normal; this.notifyIcon1.Visible=false; } }
或者这样的
private void Form1_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized)//最小化 { this.ShowInTaskbar = false; this.notifyIcon1.Visible = true; } } private void notifyIcon1_Click(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal; this.Activate(); this.notifyIcon1.Visible = false; this.ShowInTaskbar = true; } 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hanghwp/archive/2009/06/12/4263233.aspx
都有一个特点:都是将托盘的图标隐藏起来的。而不是我要的一直显示在系统的托盘上面。
以上代码如果让托盘一直显示在上面则会报错。
后找到此代码试用OK!到此解决问题。
private void mainSoftForm_SizeChanged(object sender, EventArgs e) { //判断如果是最小化时窗体隐藏 if (this.WindowState == FormWindowState.Minimized) { this.Visible = false; this.Hide(); } } private void myIcon_MouseDoubleClick(object sender, MouseEventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Visible = true; this.Show(); this.WindowState = FormWindowState.Normal; } }
这个就是我做的程序了。 使用了DevComponents.DotNetBar2.dll 的一点效果
注册码:
Admin
NLR8ZC-855444-67536856734523947(专业版)
NLR8ZO-855444-67536856215078531(标准版)
好了就这么多!这个注册码的算法于网上收集的java文件改写的。