界面比较简单,主要两个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. Windows 环境下 Redis 安装

    1.redis官方下载地址:https://redis.io/download,redis 64位下载地址:https://github.com/MicrosoftArchive/redis/rele ...

  2. Mysql数据库的安装及配置

    本文转载自http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html 如果要在Linux上做j2ee开发,首先得搭建 ...

  3. 【母函数】hdu1028 Ignatius and the Princess III

    大意是给你1个整数n,问你能拆成多少种正整数组合.比如4有5种: 4 = 4;  4 = 3 + 1;  4 = 2 + 2;  4 = 2 + 1 + 1;  4 = 1 + 1 + 1 + 1; ...

  4. [SourceTree]--记录Win10 安装SourceTree免注册登陆

    记录SourceTree一次安装不成功的过程及解决办法 SourceTree简介 按照官网介绍:SourceTree是一款用于Windows和Mac的免费Git客户端.简化了用户与Git存储(仓)库的 ...

  5. springmvc与前端数据交互实例

      一.从页面接收参数 Spring MVC接收请求提交的参数值的几种方法: 使用HttpServletRequest获取. @RequestMapping("/login.do" ...

  6. 13test04:捕鱼

    #include<iostream> using namespace std; int main() { int fish_sum,flag=1; for(fish_sum=6;flag; ...

  7. SonarQube分析报告无法上传的问题

    '); 由于SonarQube5.6 api/ce/submit 接口报以下异常,导致jenkins构建结果显示为失败~: Caused by: java.lang.NullPointerExcept ...

  8. microsoft sql server - online Resources 在线资源

  9. Docker时间和宿主同步

    通过date命令查看时间 查看主机时间 [root@localhost ~]# date 2016年 07月 27日 星期三 22:42:44 CST 查看容器时间 root@b43340ecf5ef ...

  10. html语义化小记录

    1.头部标签 <header></header> 2.大块集合 <article></article> 3.主要集和 <main></ ...