zoukankan      html  css  js  c++  java
  • C# 杂货

    后台运行

    this.ShowInTaskbar = false;//不在任务栏中显示
    this.Visibility = Visibility.Hidden;//不显示窗口

    设置右下角托盘

         //托盘小图标
            NotifyIcon notifyIcon;
            void icon() {
                string path = System.IO.Path.GetFullPath(@"Iconfavicon.ico");
                if (File.Exists(path))
                {
                    this.notifyIcon = new NotifyIcon();
                    this.notifyIcon.BalloonTipText = "Hello, 文件监视器"; //设置程序启动时显示的文本
                    this.notifyIcon.Text = "文件监视器";//最小化到托盘时,鼠标点击时显示的文本
                    System.Drawing.Icon icon = new System.Drawing.Icon(path);//程序图标 
                    this.notifyIcon.Icon = icon;
                    this.notifyIcon.Visible = true;
                    //notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick;
                    this.notifyIcon.ShowBalloonTip(1000);
                }
    
                contextMenu();
            }
            #region 托盘右键菜单
            private void contextMenu()
            {
                ContextMenuStrip cms = new ContextMenuStrip();
    
    
                //关联 NotifyIcon 和 ContextMenuStrip
                notifyIcon.ContextMenuStrip = cms;
    
                System.Windows.Forms.ToolStripMenuItem exitMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                exitMenuItem.Text = "退出";
                exitMenuItem.Click += new EventHandler(exitMenuItem_Click);
    
    
                System.Windows.Forms.ToolStripMenuItem hideMenumItem = new System.Windows.Forms.ToolStripMenuItem();
                hideMenumItem.Text = "隐藏";
                hideMenumItem.Click += new EventHandler(hideMenumItem_Click);
    
    
                System.Windows.Forms.ToolStripMenuItem showMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                showMenuItem.Text = "显示";
                showMenuItem.Click += new EventHandler(showMenuItem_Click);
    
    
                cms.Items.Add(exitMenuItem);
                cms.Items.Add(hideMenumItem);
                cms.Items.Add(showMenuItem);
            }
    
            private void exitMenuItem_Click(object sender, EventArgs e)
            {
                notifyIcon.Visible = false;
    
                System.Windows.Application.Current.Shutdown();
            }
    
            private void hideMenumItem_Click(object sender, EventArgs e)
            {
                this.Hide();
            }
    
            private void showMenuItem_Click(object sender, EventArgs e)
            {
                this.Show();
                this.Activate();
            }
            #endregion
  • 相关阅读:
    2018上C语言程序设计(高级)作业-第0次作业
    最后一次作业-- 总结报告
    第14、15教学周作业
    第七周作业
    第六周作业
    第四周作业
    C语言--第四次作业
    C语言--第三次作业
    C-语言第二次作业(大一下)
    TRY
  • 原文地址:https://www.cnblogs.com/lingLuoChengMi/p/14030355.html
Copyright © 2011-2022 走看看