您的位置:首页 > 编程语言 > C#

C#实现右下角图标(系统托盘)功能

2010-08-20 19:16 190 查看
窗体中拖入 notifyIcon 组件

notifyIcon 中的 ICON 属性 显示的图标

下面是系统托盘的基本功能代码(单击最小化窗体隐藏,双击图标显示)及窗体关闭时退出确认代码。

  //单击最小化窗体隐藏

  private void frmMain_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
notifyIcon1.Visible = true; //托盘图标隐藏
}
if (this.WindowState == FormWindowState.Minimized)//最小化事件
{
this.Hide();//最小化时窗体隐藏
}
}

//双击系统托盘的小图标事件

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal; //还原窗体
}
}

private void frmMain_FormClosing(object sender, FormClosingEventArgs e) //关闭事件
{
DialogResult result;
result = MessageBox.Show("确定退出吗?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (result == DialogResult.OK)
{

Application.ExitThread();
}
else
{
e.Cancel = true;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: