利用c#制作托盘程序,并禁止多个应用实例运行
来源:互联网 发布:淘宝模版在线制作 编辑:程序博客网 时间:2024/05/18 12:40
转载自:http://www.cnblogs.com/yjmyzz/articles/1021058.html
托盘程序的制作:
1.把NotifyIcon控件拉一个到窗体上,并设置NotifyIcon的Icon(很重要!否则运行后看不到效果)
2.窗体关闭时,将程序最小化到系统托盘上
privatevoid Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//MessageBox.Show("程序将最小化到系统托盘区");
e.Cancel= true;// 取消关闭窗体
this.Hide();
this.ShowInTaskbar= false;//取消窗体在任务栏的显示
this.notifyIcon1.Visible= true;//显示托盘图标
}
3.放一个上下文菜单,添加几个基本项,"显示主窗体","退出" ,将这个菜单挂到NotifyIcon上{
//MessageBox.Show("程序将最小化到系统托盘区");
e.Cancel= true;// 取消关闭窗体
this.Hide();
this.ShowInTaskbar= false;//取消窗体在任务栏的显示
this.notifyIcon1.Visible= true;//显示托盘图标
}
privatevoid menuShow_Click(object sender, EventArgs e)
{
this.Show();
this.ShowInTaskbar= true;
this.notifyIcon1.Visible= false;
}
privatevoid menuExit_Click(object sender, EventArgs e)
{
this.Dispose(true);
Application.ExitThread();
}
{
this.Show();
this.ShowInTaskbar= true;
this.notifyIcon1.Visible= false;
}
privatevoid menuExit_Click(object sender, EventArgs e)
{
this.Dispose(true);
Application.ExitThread();
}
4.左键单击托盘图标时,显示主窗体,右击时当然是弹出上面设置的菜单
privatevoid notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button== MouseButtons.Left)
{
this.Show();
this.ShowInTaskbar= true;
this.notifyIcon1.Visible= false;
}
}
{
if (e.Button== MouseButtons.Left)
{
this.Show();
this.ShowInTaskbar= true;
this.notifyIcon1.Visible= false;
}
}
防止这个程序同时运行多个
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace LuceneTest
{
static class Program
{
/**////<summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static 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());
}
}
}
}
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace LuceneTest
{
static class Program
{
/**////<summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static 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());
}
}
}
}
- 利用c#制作托盘程序,并禁止多个应用实例运行
- 利用c#制作托盘程序,并禁止多个应用实例运行
- C#禁止重复运行程序,并激活原托盘程序
- [转]C#禁止重复运行程序,并激活原托盘程序
- 禁止运行程序多个实例
- 关于C#禁止多个实例程序运行的详细解决
- 禁止一个程序启动多个实例
- 如何禁止程序启动多个实例
- Visaul C#托盘程序制作心得
- Visaul C#托盘程序制作心得
- Visaul C#托盘程序制作心得
- Visaul C#托盘程序制作心得
- Visaul C#托盘程序制作心得
- 禁止一个应用程序的实例在同一台机器上运行多个(C#源码)
- 禁止一个程序的多个实例同时运行的几种方法!
- C#程序在托盘后台运行
- C#程序在托盘后台运行
- C#程序在托盘后台运行
- JSP于JS的交互
- ios图书翻页效果
- c++画图(2)-初步试验调用python
- Android GridView嵌入ImageButton的问题
- Android ListView 列表控件的简单使用
- 利用c#制作托盘程序,并禁止多个应用实例运行
- 2012年5月TIOBE编程语言排行榜发布:C继续领跑
- 同一个tomcat多个web应用共享session
- transform详解
- Android ApiDemos示例解析(1):创建ApiDemo示例
- swap_ranges详解
- 黑马程序员——反射
- fill详解
- nand flash 与nor flash区别