VS2017 - Winform 简单托盘小程序
界面比较简单,主要两个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 简单托盘小程序的更多相关文章
- 输出多行字符的一个简单JAVA小程序
public class JAVA { public static void main(String[] args) { System.out.println("-------------- ...
- 简单的小程序实现ATM机操作
简单的小程序实现ATM机操作 代码如下: package Day06; import java.util.Scanner; public class TestAccount { public stat ...
- python -----一个简单的小程序(监控电脑内存,cpu,硬盘)
一个简单的小程序 用函数实现!~~ 实现: cpu 使用率大于百分之50 时 , C 盘容量不足5 G 时, 内存 低于2G 时. 出现以上其中一种情况,发送自动报警邮件! 主要运用 到了两个 模 ...
- 3.2 Lucene实战:一个简单的小程序
在讲解Lucene索引和检索的原理之前,我们先来实战Lucene:一个简单的小程序! 一.索引小程序 首先,new一个java project,名字叫做LuceneIndex. 然后,在project ...
- Python3的tkinter写一个简单的小程序
一.这个学期开始学习python,但是看了python2和python3,最后还是选择了python3 本着熟悉python的原因,并且也想做一些小程序来增加自己对python的熟练度.所以写了一个简 ...
- Python绘制PDF文件~超简单的小程序
Python绘制PDF文件 项目简介 这次项目很简单,本次项目课,代码不超过40行,主要是使用 urllib和reportlab模块,来生成一个pdf文件. reportlab官方文档 http:// ...
- WinForm版图像编辑小程序(实现图像拖动、缩放、旋转、抠图)
闲暇之余,开发一个图片编辑小程序.程序主要特点就是可方便的对多个图像编辑,实现了一些基本的操作.本文主要介绍一下程序的功能.设计思路. 执行程序 下载地址: 百度网盘.https://pan.baid ...
- 用python写个简单的小程序,编译成exe跑在win10上
每天的工作其实很无聊,早知道应该去IT公司闯荡的.最近的工作内容是每逢一个整点,从早7点到晚11点,去查一次客流数据,整理到表格中,上交给素未蒙面的上线,由他呈交领导查阅. 人的精力毕竟是有限的,所以 ...
- .NET WinForm画树叶小程序
看了一片文章(http://keleyi.com/a/bjac/nurox416.htm),是使用分型画树叶,代码是Java的,因为Java很久没弄了,改用C#实现,下载地址: 画树叶小程序下载 核心 ...
随机推荐
- POJ 3260 The Fewest Coins(背包问题)
[题目链接] http://poj.org/problem?id=3260 [题目大意] 给出你拥有的货币种类和每种的数量,商店拥有的货币数量是无限的, 问你买一个价值为m的物品,最少的货币流通数量为 ...
- [BZOJ2876]骑行川藏
以前并没有发现微积分教材上有这种东西...我还是太菜了... 其实就是要在满足$\sum\limits_{i=1}^nk_is_i(v_i-v_i')^2\leq E$的同时求$\sum\limits ...
- 【博弈论】【SG函数】【找规律】Gym - 101147A - The game of Osho
以后这种题还是不能空想,必须打个表看看,规律还是比较好找的……具体是啥看代码.用SG函数暴力的部分就不放了. #include<cstdio> using namespace std; i ...
- Exercise02_11
import javax.swing.JOptionPane; public class Population{ public static void main(String[] args){ int ...
- hadoop中URI理解
1)在编写MR程序的时候经常会有如下代码: String uri=“....”: Configuration conf=new Configuration(): FileSystem fs=FileS ...
- JavaScript异步编程的Promise模式(转)
异步模式在web编程中变得越来越重要,对于web主流语言Javascript来说,这种模式实现起来不是很利索,为此,许多Javascript库(比如 jQuery和Dojo)添加了一种称为promis ...
- 今天升级Xcode 7.0 bata发现网络访问失败。
今天升级Xcode 7.0 bata发现网络访问失败.输出错误信息 The resource could not be loaded because the App Transport Securit ...
- 可见性-volatile
出处: http://blog.csdn.net/vking_wang/article/details/9982709
- SecureCRT的一些问题解决
按下退格键发送删除命令 设置缓冲 拷贝与粘贴 多标签切换 ctrl + tab . 如果同时按下shift,可以方向切换
- 在Windows平台下安装与配置Memcached及C#使用方法
1.在Windows下安装Memcached 资料来源:http://www.jb51.net/article/30334.htm 在Windows平台下安装与配置Memcached的方法,Memca ...