界面比较简单,主要两个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());
}
}
}
}

VS2017 - Winform 简单托盘小程序的更多相关文章

  1. 输出多行字符的一个简单JAVA小程序

    public class JAVA { public static void main(String[] args) { System.out.println("-------------- ...

  2. 简单的小程序实现ATM机操作

    简单的小程序实现ATM机操作 代码如下: package Day06; import java.util.Scanner; public class TestAccount { public stat ...

  3. python -----一个简单的小程序(监控电脑内存,cpu,硬盘)

    一个简单的小程序 用函数实现!~~ 实现: cpu 使用率大于百分之50 时  ,  C 盘容量不足5 G 时, 内存 低于2G 时. 出现以上其中一种情况,发送自动报警邮件! 主要运用 到了两个 模 ...

  4. 3.2 Lucene实战:一个简单的小程序

    在讲解Lucene索引和检索的原理之前,我们先来实战Lucene:一个简单的小程序! 一.索引小程序 首先,new一个java project,名字叫做LuceneIndex. 然后,在project ...

  5. Python3的tkinter写一个简单的小程序

    一.这个学期开始学习python,但是看了python2和python3,最后还是选择了python3 本着熟悉python的原因,并且也想做一些小程序来增加自己对python的熟练度.所以写了一个简 ...

  6. Python绘制PDF文件~超简单的小程序

    Python绘制PDF文件 项目简介 这次项目很简单,本次项目课,代码不超过40行,主要是使用 urllib和reportlab模块,来生成一个pdf文件. reportlab官方文档 http:// ...

  7. WinForm版图像编辑小程序(实现图像拖动、缩放、旋转、抠图)

    闲暇之余,开发一个图片编辑小程序.程序主要特点就是可方便的对多个图像编辑,实现了一些基本的操作.本文主要介绍一下程序的功能.设计思路. 执行程序 下载地址: 百度网盘.https://pan.baid ...

  8. 用python写个简单的小程序,编译成exe跑在win10上

    每天的工作其实很无聊,早知道应该去IT公司闯荡的.最近的工作内容是每逢一个整点,从早7点到晚11点,去查一次客流数据,整理到表格中,上交给素未蒙面的上线,由他呈交领导查阅. 人的精力毕竟是有限的,所以 ...

  9. .NET WinForm画树叶小程序

    看了一片文章(http://keleyi.com/a/bjac/nurox416.htm),是使用分型画树叶,代码是Java的,因为Java很久没弄了,改用C#实现,下载地址: 画树叶小程序下载 核心 ...

随机推荐

  1. SQL Loader with utf8

    alter this line in your control file characterset UTF8 to this characterset UTF8 length semantics ch ...

  2. Hnoi2013题解 bzoj3139~3144

    话说好久没写题(解)了.. 先贴份题解:http://wjmzbmr.com/archives/hnoi-2013-%E9%A2%98%E8%A7%A3/(LJ神题解..Lazycal表示看不懂..) ...

  3. 「Baltic2015」Network

    题目描述 原文 The government of Byteland has decided that it is time to connect their little country to th ...

  4. 【分块】bzoj2957 楼房重建

    http://www.cnblogs.com/wmrv587/p/3843681.html ORZ 分块大爷.思路很神奇也很清晰. 把 块内最值 和 块内有序 两种良好的性质结合起来,非常棒地解决了这 ...

  5. 【后缀数组】bzoj2217 Secretary

    考虑简化问题:计算一个字符串中至少出现两次的最长子串.答案一定会在sa中相邻两个后缀的lcp中.因为后缀的位置在sa中相距越远,其lcp的长度就越短,这是由于字典序的性质决定的. 于是,在s1和s2中 ...

  6. NHibernate官方文档中文版——持久化类(Persistent Classes)

    持久化类是一个应用程序中的类,主要用来实现业务逻辑(例如,在电商应用中的客户和订单类).持久化类,就像它的名字一样,生命周期短暂并且用来持久化的据库对象实例. 如果这些类的构造能够依照一些简单的原则, ...

  7. oracle--v$lock type字段详解

    Name Description AD ASM Disk AU Lock AF Advisor Framework AG Analytic Workspace Generation AK GES De ...

  8. mysql 5.7.20解压版安装配置

    MySql 5.7.20版本免安装版配置过程   下载地址为: https://dev.mysql.com/downloads/mysql/ 最下面根据自己的操作系统选择合适的型号 下载完以后解压缩到 ...

  9. SQLSERVER调用DLL程序

    在SQL Server中调用dll分为两个步骤 1.创建一个dll文件(dll文件分成3种类型,讲其中一种) 2.把dll文件放进SQL Server的程序集中.然后定义一个Function,就可以通 ...

  10. ubuntu中wifi显示被硬件禁用的解决方法

    本人使用的电脑是华硕X550C,安装了ubuntu16.04版本. 联网的时候显示“wifi已经通过硬件开关禁用”.按Fn+F2无法开启wifi.通过rfkill命令无法也无法开启wifi. 经过了解 ...