C# NotifyIcon控件问题

来源:百度知道 编辑:UC知道 时间:2024/06/25 10:39:23
怎么让窗体程序,运行时直接出现在系统托盘运行的后台程序

就是一开始运行,只有托盘上显示图标,我点击它一下才跳出应用窗体

以下代码在VS2008编译通过并大致符合您的要求 ,右上角的X不关闭,直接隐藏窗体,双击任务栏的图标就可以实现显示了(记得为NotifyIcon设置icon)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Win_temp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.Hide();
this.ShowInTaskbar = false;
}

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
this.Hide();
e.Cancel = true ;
}

}
}

记得要正确添加事件谢谢

就是你说的那个控件就可以了