zoukankan      html  css  js  c++  java
  • C# 控制台程序 托盘图标 事件响应

    static void Main(string[] args)
    {

    NotifyIconHelper ni = new NotifyIconHelper();
    NotifyIconHelper.ShowNotifyIcon();

    while (true)
    {
    Application.DoEvents();
    }

    }

    ----------------------------

    namespace ConsoleHideShow
    {
    /// <summary>
    /// 系统图标操作
    /// </summary>
    public class NotifyIconHelper
    {
    public NotifyIconHelper()
    {
    _NotifyIcon.Icon = new Icon(@"C:1.ico");
    _NotifyIcon.Visible = false;
    _NotifyIcon.Text = "tray";

    ContextMenu menu = new ContextMenu();
    MenuItem item = new MenuItem();
    item.Text = "右键菜单,还没有添加事件";
    item.Index = 0;

    menu.MenuItems.Add(item);
    _NotifyIcon.ContextMenu = menu;

    _NotifyIcon.MouseDoubleClick += new MouseEventHandler(_NotifyIcon_MouseDoubleClick);
    }
    static void _NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
    {
    Console.WriteLine("托盘被双击.");
    }

    #region 托盘图标
    static NotifyIcon _NotifyIcon = new NotifyIcon();
    public static void ShowNotifyIcon()
    {
    _NotifyIcon.Visible = true;
    _NotifyIcon.ShowBalloonTip(3000, "", "我是托盘图标,用右键点击我试试,还可以双击看看。", ToolTipIcon.None);
    }
    public static void HideNotifyIcon()
    {
    _NotifyIcon.Visible = false;
    }

    #endregion

    }
    }

    参考》http://www.cnblogs.com/bruceli/archive/2011/04/28/2031584.html

  • 相关阅读:
    Intersection of Two Linked Lists
    Tools:实现vmware虚拟机开机自启动
    Tools:实现ping操作带时间戳【windows+linux】
    Django:学习笔记
    Python:笔记2
    Python:笔记1_字符串处理【转载】
    Pycharm:使用笔记
    python:win下将py文件打包成exe
    python:选房抽签小工具
    RF:操作笔记
  • 原文地址:https://www.cnblogs.com/aiqingqing/p/4556824.html
Copyright © 2011-2022 走看看