C#.NET中如何编写托盘程序 好象有个notification类,还有他自己有个控件,你可以拖到form就可以 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 添加 NotifyIcon,设定你在托盘的图标 把form 的 showintoolbar 设为 false private void ntIcon_DoubleClick(object sender, System.EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Visible=true; this.WindowState = FormWindowState.Normal; this.Activate(); } else { WindowState=FormWindowState.Minimized; this.Visible=false; } } private void fm_Main_Resize(object sender, System.EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Visible = false; this.notifyIcon1.Icon = this.Icon; this.notifyIcon1.Text = this.Text; this.notifyIcon1.Visible = true; } }private void notifyIcon1_Click(object sender, System.EventArgs e) { this.Visible = true; this.WindowState = FormWindowState.Normal; this.notifyIcon1.Visible = false;} http://www.csdn.net/Develop/Read_Article.asp?Id=20992 点击关闭,隐藏窗体显示托盘的图标, 双击图标打开窗体private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e){ e.Cancel =true; this.Hide (); this.notifyIcon1.Visible =true; }private void notifyIcon1_DoubleClick(object sender, System.EventArgs e){ if(this.Visible ==true) //根据窗口的显示和隐藏设置Trayico对象的显示 { this.Hide(); this.notifyIcon1 .Visible =true; } else { this.Show(); this.notifyIcon1.Visible =false; }} 将上下文菜单notification关联上 http://www.yesky.com/20020110/213425.shtml public Form1(){//// Required for Windows Form Designer support//InitializeComponent();//// TODO: Add any constructor code after InitializeComponent call//m_bFlag=true;m_bShowWnd=true;try{m_Icon1 = new Icon("Icon1.ico");//导入图标文件m_Icon2 = new Icon("Icon2.ico");}catch ( Exception e ){MessageBox.Show("Error " + e.Message,"Animate Tray - Error");menuItem2.Enabled = false;menuItem3.Enabled = false;}}添加menuItem1、menuItem2、menuItem3、m_trayIcon的Click事件,消息处理函数如下:private void menuItem1_Click(object sender, System.EventArgs e){timer1.Start();//打开计时器}private void menuItem2_Click(object sender, System.EventArgs e){timer1.Stop();//停止计时器}private void menuItem3_Click(object sender, System.EventArgs e){Application.Exit();//退出应用程序}private void m_trayIcon_Click(object sender, System.EventArgs e){if(m_bShowWnd == true)//隐藏主界面{this.Visible = false;m_bShowWnd = false;}else//显示主界面{this.Visible = true;m_bShowWnd = true;}} 最后还要添加timer1的Tick()函数: private void timer1_Tick(object sender, System.EventArgs e){if ( m_Icon1 != null && m_Icon2 != null ) //如果两个图标文件都被正确载入{//只要timer1被启动,则在两个图标之间不断进行选择变换,实现动画效果if ( m_bFlag == true ){m_trayIcon.Icon = m_Icon2;m_bFlag = false;}else{m_trayIcon.Icon = m_Icon1;m_bFlag = true;}}} ◆带变量的通配符如何写法◆ 大牛们啊.局域网版程序整成单机版都要考虑些什么问题啊?长长长长! datagridview中行标头的那一列(也就是最左边的那一列)的最上面一个单元格填数,如何做呢? 利用多线程从长时间运行的操作中分离出用户界面的问题 如何调用另一个页面中的ID? listview计算列和的问题 求字符串的格式修改!!!! 求助:关于数据库中image图片读取的问题 关于异步通讯的问题(续) HttpWebResponse如何获取持久性cookie、求大神赐教 我应不应该转学c#? 求WinForm中C#写的管理软件
添加 NotifyIcon,设定你在托盘的图标 把form 的 showintoolbar 设为 false
private void ntIcon_DoubleClick(object sender, System.EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Visible=true; this.WindowState = FormWindowState.Normal; this.Activate(); } else { WindowState=FormWindowState.Minimized; this.Visible=false; } }
private void fm_Main_Resize(object sender, System.EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Visible = false; this.notifyIcon1.Icon = this.Icon; this.notifyIcon1.Text = this.Text; this.notifyIcon1.Visible = true; } }private void notifyIcon1_Click(object sender, System.EventArgs e) { this.Visible = true; this.WindowState = FormWindowState.Normal; this.notifyIcon1.Visible = false;}
{
e.Cancel =true;
this.Hide ();
this.notifyIcon1.Visible =true;
}private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
if(this.Visible ==true) //根据窗口的显示和隐藏设置Trayico对象的显示
{
this.Hide();
this.notifyIcon1 .Visible =true;
}
else
{
this.Show();
this.notifyIcon1.Visible =false;
}
}
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
m_bFlag=true;
m_bShowWnd=true;try
{
m_Icon1 = new Icon("Icon1.ico");//导入图标文件
m_Icon2 = new Icon("Icon2.ico");
}
catch ( Exception e )
{
MessageBox.Show("Error " + e.Message,"Animate Tray - Error");
menuItem2.Enabled = false;
menuItem3.Enabled = false;
}
}添加menuItem1、menuItem2、menuItem3、m_trayIcon的Click事件,消息处理函数如下:
private void menuItem1_Click(object sender, System.EventArgs e)
{
timer1.Start();//打开计时器
}private void menuItem2_Click(object sender, System.EventArgs e)
{
timer1.Stop();//停止计时器
}private void menuItem3_Click(object sender, System.EventArgs e)
{
Application.Exit();//退出应用程序
}private void m_trayIcon_Click(object sender, System.EventArgs e)
{
if(m_bShowWnd == true)//隐藏主界面
{
this.Visible = false;
m_bShowWnd = false;
}
else//显示主界面
{
this.Visible = true;
m_bShowWnd = true;
}
}
最后还要添加timer1的Tick()函数: private void timer1_Tick(object sender, System.EventArgs e)
{
if ( m_Icon1 != null && m_Icon2 != null ) //如果两个图标文件都被正确载入
{
//只要timer1被启动,则在两个图标之间不断进行选择变换,实现动画效果
if ( m_bFlag == true )
{
m_trayIcon.Icon = m_Icon2;
m_bFlag = false;
}
else
{
m_trayIcon.Icon = m_Icon1;
m_bFlag = true;
}
}
}