托盤程式的制作:
1.把notifyicon控件拉一個到窗體上,并設定notifyicon的icon(很重要!否則運作後看不到效果)
2.窗體關閉時,将程式最小化到系統托盤上
private
void form1_formclosing(object sender, formclosingeventargs e)
{
//messagebox.show("程式将最小化到系統托盤區");
e.cancel
= true;
// 取消關閉窗體
this.hide();
this.showintaskbar
= false;//取消窗體在工作列的顯示
this.notifyicon1.visible
= true;//顯示托盤圖示
}
3.放一個上下文菜單,添加幾個基本項,"顯示主窗體","退出" ,将這個菜單挂到notifyicon上
void menushow_click(object sender, eventargs e)
this.show();
= false;
void menuexit_click(object sender, eventargs e)
this.dispose(true);
application.exitthread();
4.左鍵單擊托盤圖示時,顯示主窗體,右擊時當然是彈出上面設定的菜單
void notifyicon1_mouseclick(object sender, mouseeventargs e)
if (e.button
== mousebuttons.left)
防止這個程式同時運作多個
using system;
using system.collections.generic;
using system.windows.forms;
using system.threading;
namespace lucenetest
static
class program
/**////
<summary>
/// 應用程式的主入口點。
///
</summary>
[stathread]
void main()
bool bcreatednew;
mutex m
= new mutex(false,
"product_index_cntvs",
out bcreatednew);
if (bcreatednew)
application.enablevisualstyles();
application.setcompatibletextrenderingdefault(false);
application.run(new form1());