zoukankan      html  css  js  c++  java
  • 托盘

            #region 全局变量
            //创建NotifyIcon对象 
            NotifyIcon notifyIcon = new NotifyIcon();
            d.Icon ico = new d.Icon("../../ico/logo_x.ico");
            d.Image img = null;
            ContextMenuStrip conTextMenuStrip = new ContextMenuStrip();
            List<ToolStripMenuItem> toolStripMenuItem = new List<ToolStripMenuItem>();
            const string Red = "Red";
            const string Green = "Green";
            const string Blue = "Blue";
            const string Yellow = "Yellow";
            #endregion
    
            #region 加载
            public DelegateControlUpdateOne()
            {
                InitializeComponent();
                //加载图片 
                notifyIcon.Icon = ico;
                //隐藏任务栏区图标 
                this.ShowInTaskbar = false;
                //图标显示在托盘区 
                notifyIcon.Visible = true;
                //添加托盘菜单项 
                conTextMenuStrip.ShowImageMargin = true;
                img = d.Image.FromFile("../../ico/logo_x.ico");
                CreateItem("红色", Red);
                CreateItem("蓝色", Blue);
                CreateItem("绿色", Green);
                CreateItem("黄色", Yellow);
                conTextMenuStrip.Items.AddRange(toolStripMenuItem.ToArray());
                //托盘菜单项在图标右键时显示  
                notifyIcon.ContextMenuStrip = conTextMenuStrip;
                //委托点击事件
                this.Closed += DelegateControlUpdateOne_Closed;
            }
             #endregion
    
            #region CreateItem(string text, string tag)
            /// <param name="text">text</param>
            /// <param name="tag">颜色</param>
            void CreateItem(string text, string tag)
            {
                ToolStripMenuItem toolStripMenuitem = new ToolStripMenuItem("白色", img);
                toolStripMenuitem.Click += toolStripMenuitem_Click;
                toolStripMenuitem.Tag = tag;
                toolStripMenuItem.Add(toolStripMenuitem);
            }
            #endregion
    
            #region 改变颜色
            void toolStripMenuitem_Click(object sender, EventArgs e)
            {
                ToolStripMenuItem item = sender as ToolStripMenuItem;
                if (item == null) return;
                switch (item.Tag.ToString())
                {
                    case Red: Hint.Background = Brushes.Red; break;
                    case Blue: Hint.Background = Brushes.Blue; break;
                    case Yellow: Hint.Background = Brushes.Yellow; break;
                    case Green: Hint.Background = Brushes.Green; break;
                }
            }
            #endregion
    
            #region  清空窗体 DelegateControlUpdateOne_Closed(object sender, EventArgs e)
            void DelegateControlUpdateOne_Closed(object sender, EventArgs e)
            {
                notifyIcon.Dispose();
                notifyIcon = null;
            }
            #endregion
    
  • 相关阅读:
    _ 下划线 Underscores __init__
    Page not found (404) 不被Django的exception中间件捕捉 中间件
    从装修儿童房时的门锁说起
    欧拉定理 费马小定理的推广
    线性运算 非线性运算
    Optimistic concurrency control 死锁 悲观锁 乐观锁 自旋锁
    Avoiding Full Table Scans
    批量的单向的ssh 认证
    批量的单向的ssh 认证
    Corrupted MAC on input at /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux/Net/SSH/Perl/Packet.pm l
  • 原文地址:https://www.cnblogs.com/zhubaobao/p/3892627.html
Copyright © 2011-2022 走看看