1. 界面控件
1-1 新建窗体一个
1-2 控件 notifyIcon
添加单击事件 xxx_Click 见下面代码
2. 效果图
3. 源码 可以点击这里 下载源码
//窗体大小改变事件
private void Form1_SizeChanged(object sender, EventArgs e)
{
try
{
//最小化
if (this.WindowState == FormWindowState.Minimized)
{
//不显示窗体
this.ShowInTaskbar = false;
//托盘可见
this.notifyIcon1.Visible = true;
//气球提示
this.notifyIcon1.ShowBalloonTip(3, "提示", "系统仍在运行!\n如要打开,请点击图标", ToolTipIcon.Info);
}
}
catch (Exception ex)
{
}
}
//加载事件
private void Form1_Load(object sender, EventArgs e)
{
InitializeComponent();
try
{
this.Text = "实现最小托盘";
//this.notifyIcon1.Icon = new Icon("技术管理.ico");//设置当前图标
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
notifyIcon1.Icon = new Icon("技术管理.ico");//指定一个图标
notifyIcon1.Visible = false;
notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
}
catch (Exception ex)
{
}
}
private void notifyIcon1_Click(object sender, EventArgs e)
{
try
{
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
this.Activate();
this.notifyIcon1.Visible = false;
this.ShowInTaskbar = true;
}
catch (Exception ex)
{
}
}
注:部分代码来源网络 基础上我添加修改了部分,有不足之处 请发表评论
希望对你有所帮助