• VS2017


     界面比较简单,主要两个button 一个NotifyIcon 和 右键菜单 控件,

    NotifyIcon 属性,如下:

    并为NotifyIcon指定了DoubleClick事件:

    主窗体增加两个事件:

    整体代码如下:

    using Pallet_Common;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Pallet_01
    {
        public partial class MainForm : Form
        {
    
            public MainForm()
            {
                InitializeComponent();
                this.btnEnd.Enabled = false;
                this.停止ToolStripMenuItem.Enabled = false;
            }
    
            private void MainForm_Load(object sender, EventArgs e)
            {
                this.btnEnd.Enabled = false;
                this.Resize += MainForm_Resize;
    
            }
    
    
            //单击窗体最小化时窗体隐藏 
            void MainForm_Resize(object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.Hide();
                }
            }
    
            private void NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                this.Show(); // 窗体显现
                this.WindowState = FormWindowState.Normal; //窗体回复正常大小
            }
    
            private void btnStart_Click(object sender, EventArgs e)
            {
    
                Scheduler.StartUp();
                this.btnStart.Enabled = false;
                this.btnEnd.Enabled = true;
                this.启动ToolStripMenuItem.Enabled = false;
                this.停止ToolStripMenuItem.Enabled = true;
    
                string pageSize = ConfigurationManager.AppSettings["PageSize"];
                this.lblCount.Text = pageSize + "";
    
                this.lblCount.Update();
    
            }
    
            private void btnEnd_Click(object sender, EventArgs e)
            {
    
                Scheduler.Stop();
                this.btnStart.Enabled = true;
                this.btnEnd.Enabled = false;
                this.启动ToolStripMenuItem.Enabled = true;
                this.停止ToolStripMenuItem.Enabled = false;
    
                this.lblCount.Text = "----";
                this.lblCount.Update();
            }
    
    
            private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
            {
                if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    //关闭所有的线程,释放占用内存
                    this.Dispose();
                    this.Close();
                }
                else
                {
                    e.Cancel = true;
                }
            }
    
            #region 右键菜单事件
            private void 启动ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Scheduler.StartUp();
                this.btnStart.Enabled = false;
                this.btnEnd.Enabled = true;
                this.启动ToolStripMenuItem.Enabled = false;
                this.停止ToolStripMenuItem.Enabled = true;
            }
    
            private void 停止ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Scheduler.Stop();
                this.btnStart.Enabled = true;
                this.btnEnd.Enabled = false;
                this.启动ToolStripMenuItem.Enabled = true;
                this.停止ToolStripMenuItem.Enabled = false;
            }
    
            private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("是否确认退出程序?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    // 关闭所有的线程,释放占用内存
                    this.Dispose();
                    this.Close();
                }
            }
            #endregion
        }
    }

    其中打开一个程序后,不允许再次打开,也就是运行后,只能运行一个,如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Pallet_01
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                bool bCreateNew;
                Mutex m = new Mutex(false, "Pallent_01", out bCreateNew);
                if (bCreateNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
            }
        }
    }
  • 相关阅读:
    python3.0与python2.0有哪些不同
    python常用内置模块,执行系统命令的模块
    06python 之基本数据类型
    python语言简介、解释器、字符编码介绍
    http协议&接口规范&接口测试入门
    基于APPIUM测试微信公众号的UI自动化测试框架(结合Allure2测试报告框架)
    SQL注入工具sqlmap的注入过程记录
    unittest框架
    测试转型之路--学习ing
    Tomcat分析-启动过程
  • 原文地址:https://www.cnblogs.com/Violety/p/9469920.html
Copyright © 2020-2023  润新知