界面比较简单,主要两个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. Java异常处理机制及两种异常的区别

    java异常处理机制主要依赖于try,catch,finally,throw,throws五个关键字.   try 关键字后紧跟一个花括号括起来的代码块,简称try块.同理:下面的也被称为相应的块. ...

  2. 【AC自动机】【状压dp】hdu2825 Wireless Password

    f(i,j,S)表示当前字符串总长度为i,dp到AC自动机第j个结点,单词集合为S时的方案数. 要注意有点卡常数,注意代码里的注释. #include<cstdio> #include&l ...

  3. 【枚举约数】HackerRank - Week of Code 26 - Satisfactory Pairs

    题意:给你一个正整数n,问你存在多少个正整数对a,b(a<b),满足条件:存在正整数x,y,使得ax+by=n. 就预处理出n以内所有数的约数,然后暴力枚举a,暴力枚举x,然后枚举n-ax的所有 ...

  4. MySQL json 类型操作快速入门

    MySQL 5.7.8开始支持 json类型. create table t(id int,js json,PRIMARY KEY (`id`)) 插入数据insert into t values(1 ...

  5. python基础-匿名函数、内置函数、正则表达式、模块

    1. 匿名函数 1.1 有名函数 有名函数:定义了一个函数名,函数名指向内存地址:通过函数名进行访问.函数名加括号就可以运行有名函数,例如:func() def func(x, y, z = 1): ...

  6. Problem M: 第几天——C语言初学者百题大战之十八

    #include<stdio.h> int main() { int a,b,c,s; scanf("%d-%d-%d",&a,&b,&c); ...

  7. [转] matlab获取时间日期

    原文:EmanLee, Eman Lee's Space (blog, website) 在MATLAB中得到系统当前日期.时间也是经常用到的内容,由以下函数实现. 1.生成指定格式日期和时间 dat ...

  8. win下写任务提交给集群

    一,复制和删除hdfs中的文件 import org.apache.hadoop.fs.{FileSystem, Path} import org.apache.spark.{SparkConf, S ...

  9. java压缩 GZIP进行简单压缩,ZIP进行多文件保存

    java压缩  GZIP进行简单压缩,ZIP进行多文件保存 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlhbmdydWkxOTg4/font/5a6 ...

  10. sqlite3 解决并发读写冲突的问题

    #include "stdafx.h" #include "sqlite3.h" #include <iostream> #include < ...