110,538
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace NotifyIconDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Resize += new EventHandler(FormResize);
InitNotifyIcon(this.notifyIcon1);
}
private void FormResize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Visible = false;//最小化窗体时隐藏主界面
this.notifyIcon1.ShowBalloonTip(2000);//提示可以从托盘打开界面
}
}
private void InitNotifyIcon(NotifyIcon notifyIcon)
{
notifyIcon.Visible = true;
notifyIcon.Icon = new Icon("ICO.ico");
notifyIcon.BalloonTipTitle = "温馨提示:";
notifyIcon.BalloonTipText = "在这里右键可以重新打开界面";
notifyIcon.Text = "NotifyIcon应用示例";
ContextMenuStrip contextMenu = new ContextMenuStrip();
ToolStripMenuItem itemShwo = new ToolStripMenuItem();
itemShwo.Click += new EventHandler(itemShwo_Click);
itemShwo.Text = "打开主界面";
ToolStripMenuItem itemExit = new ToolStripMenuItem();
itemExit.Click += new EventHandler(itemExit_Click);
itemExit.Text = "退出程序";
contextMenu.Items.Add(itemShwo);
contextMenu.Items.Add(itemExit);
notifyIcon1.ContextMenuStrip = contextMenu;//设置右键菜单
}
private void itemExit_Click(object sender, EventArgs e)
{
Application.Exit();//退出程序
}
private void itemShwo_Click(object sender, EventArgs e)
{
this.Show();
}
}
}
//托盘图标
notifyIcon1.Icon = this.Icon;
notifyIcon1.Text = "工作全能工具";
notifyIcon1.Visible = true;
那个啥 新建一个notifyIcon1 在程序加载时候写入上面的东西..
再建一个 contextMenuStrip1 目录 里面写需要的功能..
然后 在notifyIcon1上contextMenuStrip属性 绑定contextMenuStrip1