C#实现托盘应用程序
2010-03-29 18:09
411 查看
下面是我根据网络上的应用程序改编的一个简单的托盘程序的DEMO,实现了一般托盘程序的基本功能
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication4
{
public partial class Form1 : Form
{
private Icon mNetIcon = new Icon("appMain.ico");
private NotifyIcon TrayIcon;
private ContextMenu notifyiconMnu;
public Form1()
{
InitializeComponent();
Initializenotifyicon();
}
private void Form1_Load(object sender, EventArgs e)
{
this.MaximizeBox = false;
this.MinimizeBox = false;
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
}
private void Initializenotifyicon()
{
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon();
TrayIcon.Icon = mNetIcon;
TrayIcon.Text = "用Visual C#做托盘程序";
TrayIcon.Visible = true;
TrayIcon.Click += new System.EventHandler(this.click);
////定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem[] mnuItms = new MenuItem[1];
mnuItms[0] = new MenuItem();
mnuItms[0].Text = "退出系统";
mnuItms[0].Click += new System.EventHandler(this.showmessage);
notifyiconMnu = new ContextMenu(mnuItms);
TrayIcon.ContextMenu = notifyiconMnu;
////为托盘程序加入设定好的ContextMenu对象
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
TrayIcon.Visible = false;
}
public void click(object sender, System.EventArgs e)
{
MessageBox.Show("Visual C#编写托盘程序中的事件响应");
}
public void showmessage(object sender, System.EventArgs e)
{
MessageBox.Show("你选择了退出系统!");
this.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication4
{
public partial class Form1 : Form
{
private Icon mNetIcon = new Icon("appMain.ico");
private NotifyIcon TrayIcon;
private ContextMenu notifyiconMnu;
public Form1()
{
InitializeComponent();
Initializenotifyicon();
}
private void Form1_Load(object sender, EventArgs e)
{
this.MaximizeBox = false;
this.MinimizeBox = false;
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
}
private void Initializenotifyicon()
{
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon();
TrayIcon.Icon = mNetIcon;
TrayIcon.Text = "用Visual C#做托盘程序";
TrayIcon.Visible = true;
TrayIcon.Click += new System.EventHandler(this.click);
////定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
MenuItem[] mnuItms = new MenuItem[1];
mnuItms[0] = new MenuItem();
mnuItms[0].Text = "退出系统";
mnuItms[0].Click += new System.EventHandler(this.showmessage);
notifyiconMnu = new ContextMenu(mnuItms);
TrayIcon.ContextMenu = notifyiconMnu;
////为托盘程序加入设定好的ContextMenu对象
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
TrayIcon.Visible = false;
}
public void click(object sender, System.EventArgs e)
{
MessageBox.Show("Visual C#编写托盘程序中的事件响应");
}
public void showmessage(object sender, System.EventArgs e)
{
MessageBox.Show("你选择了退出系统!");
this.Close();
}
}
}
相关文章推荐
- C#Windows 窗体设计-实现欢迎界面-显示About窗体-在托盘中写入应用程序图标
- 使用C# 完美实现多语言版本Windows应用程序
- C#实现窗口最小化到系统托盘
- [导入]如何使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- 用托盘控制windows服务的c#实现
- 单点登录方案+c#实现不同应用程序通讯,摸拟按键并跳过登录界面
- C#实现P2P应用程序
- VC++6.0中实现将应用程序的图标加入到Windows的系统托盘中
- C#实现窗口最小化到系统托盘
- C#实现托盘图标
- C#之使用NotifyIcon实现任务栏托盘菜单,图标闪烁效果及气泡提示 很多程序是只需要后台运行的,甚至不需要自己的应用界面。NotifyIcon提供了程序在任务栏的显示功能 程序下载链接如下
- WinForm+C#代码实现控制应用程序自启动功能
- C#做窗体应用程序时,对excel涉及的背景色设置,边框设置,数据如何导入等的实现
- C#应用程序实现单例模式
- C# API 应用(根据句柄,实现向另一应用程序登录窗体实现登录)
- 使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- C#实现闪动托盘
- C#实现WinForm程序的动态系统托图标 关闭主窗体时最小化到系统托盘
- C#WinForm应用程序实现自动填充网页上的用户名和密码并点击登录按钮
- C#实现桌面应用程序简单的计算器