在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
C#在托盘显示图标 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 notifyIconShow
{ public partial class notifyIconShow : Form { public notifyIconShow()
{ InitializeComponent(); } #region//设置鼠标放在托盘图标上面的文字
/// <summary>
/// 方法名称:notifyIconShow_Load(窗体加载事件)
/// 方法作用:设置鼠标放在托盘图标上面的文字
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIconShow_Load(object sender, EventArgs e) { //设置鼠标放在托盘图标上面的文字
this.notifyIcon1.Text = "这是托盘图标"; } #endregion
#region//创建对象及声明变量
//创建NotifyIcon对象
NotifyIcon notifyicon = new NotifyIcon();
//创建托盘图标对象
Icon ico = new Icon("Clock2.ico"); //创建托盘菜单对象
ContextMenu notifyContextMenu = new ContextMenu();
#endregion
#region//隐藏任务栏图标,显示托盘图标
/// <summary>
/// 方法名称:notifyIconShow_SizeChanged(窗体大小改变后事件)
/// 方法作用:隐藏任务栏图标,显示托盘图标
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIconShow_SizeChanged(object sender, EventArgs e) { //判断是否选择的是最小化按钮
if (WindowState == FormWindowState.Minimized)
{ //托盘显示图标等于托盘图标对象
//注意notifyIcon1是控件的名字而不是对象的名字
notifyIcon1.Icon = ico; //隐藏任务栏区图标
this.ShowInTaskbar = false; //图标显示在托盘区
notifyicon.Visible = true;
} } #endregion
#region//还原窗体
/// <summary>
/// 方法名称:notifyIcon1_Click(托盘图标单击)
/// 方法作用:还原窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notifyIcon1_Click(object sender, EventArgs e) { //判断是否已经最小化于托盘
if (WindowState == FormWindowState.Minimized)
{ //还原窗体显示
WindowState = FormWindowState.Normal; //激活窗体并给予它焦点
this.Activate();
//任务栏区显示图标
this.ShowInTaskbar = true; //托盘区图标隐藏
notifyicon.Visible = false;
} } #endregion
} } |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论