• 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
  • 相关阅读:
    根据输入参数,判定时间范围CheckTimeSpan
    C#登出系统并清除Cookie
    MySQL中使用group_concat遇到的坑
    MySQL中group by 与 order by 一起使用排序问题
    使用VMware安装CentOS 7
    VMware安装Linux提示此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态
    Yii2处理密码加密及验证
    Yii2 的安装及简单使用
    git merge的使用
    PHP中上传文件打印错误,错误类型
  • 原文地址:https://www.cnblogs.com/lingLuoChengMi/p/14030355.html
Copyright © 2020-2023  润新知