保护视力,我写的一个定时提醒的小玩意。


做程序员2年了,感觉视力越来越差。有时候常常工作到忘记休息。于是就想写一个能够定时提醒的小东西(公司不让从网络下载别的程序)。
功能:
    1.能够每隔一段时间提醒我休息,做做眼保健操。
    2.能够自己设定时间间隔.
   
运行环境:.net framework 2.0

使用说明:
双击托盘 重新设定。
右键托盘 可以推出程序。
主界面如图,

 

能够设定提醒的时间间隔,以秒记,我一般设置为1800,半个小时,默认为半个小时。
设定后点击ok,关闭主窗口,任务栏会有个托盘。

实现原理:

启动一个新线程,让其sleep所设置的时间间隔的长度,然后弹出对话框。

 

 

下面是代码文件:只有一个类TimeNotifier

有三个PartialClass  TimeNotifier.cs,  TimeNotifier.event.cs,TimeNotifier.Designer.cs

 

TimeNotifier.cs

 

ContractedBlock.gifExpandedBlockStart.gifCode
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Text;
 7using System.Windows.Forms;
 8
 9namespace TimeNotifier
10ExpandedBlockStart.gifContractedBlock.gif{
11    public partial class TimeNotifier : Form
12ExpandedSubBlockStart.gifContractedSubBlock.gif    {
13ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
14        /// Const
15        /// </summary>

16        public class ConstDefs
17ExpandedSubBlockStart.gifContractedSubBlock.gif        {
18            internal static int DefaultSlot = 1800;
19            internal static int OneThousant = 1000;
20        }

21
22ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
23        /// Constructor
24        /// </summary>

25        public TimeNotifier()
26ExpandedSubBlockStart.gifContractedSubBlock.gif        {
27            InitializeComponent();
28            SetDefault();
29            RegisterEvent();
30            TimeReminder();
31        }

32
33ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
34        /// Exit
35        /// </summary>
36        /// <param name="sender"></param>
37        /// <param name="e"></param>

38        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
39ExpandedSubBlockStart.gifContractedSubBlock.gif        {
40            this.newTimeThread.Abort();
41            Application.Exit();
42        }

43
44ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
45        /// Reset
46        /// </summary>
47        /// <param name="sender"></param>
48        /// <param name="e"></param>

49        private void resetToolStripMenuItem_Click(object sender, EventArgs e)
50ExpandedSubBlockStart.gifContractedSubBlock.gif        {
51            this.Show();
52        }

53
54        private void btnCancel_Click(object sender, EventArgs e)
55ExpandedSubBlockStart.gifContractedSubBlock.gif        {
56            this.Hide();
57        }

58    }

59}

 

TimeNotifier.event.cs

 

ContractedBlock.gifExpandedBlockStart.gifCode
 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using System.Drawing;
 5using System.ComponentModel;
 6using System.Windows.Forms;
 7using System.Threading;
 8
 9namespace TimeNotifier
10ExpandedBlockStart.gifContractedBlock.gif{
11    public partial class TimeNotifier
12ExpandedSubBlockStart.gifContractedSubBlock.gif    {
13ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
14        /// 注册事件.
15        /// </summary>

16        private void RegisterEvent()
17ExpandedSubBlockStart.gifContractedSubBlock.gif        {
18            this.Closing += new System.ComponentModel.CancelEventHandler(Tray_Closing);
19            this.Apply.Click += new EventHandler(Apply_Click);
20        }

21
22ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
23        /// Closing
24        /// </summary>
25        /// <param name="sender"></param>
26        /// <param name="e"></param>

27        private void Tray_Closing(object sender, CancelEventArgs e)
28ExpandedSubBlockStart.gifContractedSubBlock.gif        {
29            this.Hide();
30            e.Cancel = true;
31        }

32
33ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
34        /// Reset
35        /// </summary>
36        /// <param name="sender"></param>
37        /// <param name="e"></param>

38        private void Apply_Click(object sender, EventArgs e)
39ExpandedSubBlockStart.gifContractedSubBlock.gif        {
40            this.timeSlot = Int32.Parse(this.textBox1.Text);
41            this.newTimeThread.Abort();
42            this.TimeReminder();
43        }

44
45
46ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary> 
47        /// Set Tray 
48        /// </summary> 

49        private void SetDefault()
50ExpandedSubBlockStart.gifContractedSubBlock.gif        {
51            timeSlot = ConstDefs.DefaultSlot;
52            this.textBox1.Text = timeSlot.ToString();
53        }

54
55ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
56        /// 启动新线程.
57        /// </summary>

58        private void TimeReminder()
59ExpandedSubBlockStart.gifContractedSubBlock.gif        {
60            if (newTimeThread != null)
61ExpandedSubBlockStart.gifContractedSubBlock.gif            {
62                newTimeThread.Abort();
63            }

64            newTimeThread = new Thread(new ThreadStart(TimeNotice));
65            newTimeThread.Start();
66        }

67
68        private void TimeNotice()
69ExpandedSubBlockStart.gifContractedSubBlock.gif        {
70            while (true)
71ExpandedSubBlockStart.gifContractedSubBlock.gif            {
72                Thread.Sleep(this.timeSlot * ConstDefs.OneThousant);
73                MessageBox.Show("Time to have a rest" + DateTime.Now.ToString());
74
75            }

76        }

77    }

78
79
80}

 

TimeNotifier.Designer.cs

ContractedBlock.gifExpandedBlockStart.gifCode
  1using System;
  2using System.Collections.Generic;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Drawing;
  6using System.Text;
  7using System.Windows.Forms;
  8using System.Threading;
  9
 10namespace TimeNotifier
 11ExpandedBlockStart.gifContractedBlock.gif{
 12    public partial class TimeNotifier
 13ExpandedSubBlockStart.gifContractedSubBlock.gif    {
 14ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary> 
 15        /// Required designer variable. 
 16        /// </summary> 

 17        private System.ComponentModel.IContainer components = null;
 18        private NotifyIcon TrayIcon;
 19        private ContextMenu TrayMenu;
 20        private MenuItem subMenuExit;
 21        private MenuItem subMenuReset;
 22        private int timeSlot;
 23        private Thread newTimeThread;
 24
 25ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary> 
 26        /// Clean up any resources being used. 
 27        /// </summary> 
 28        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 

 29        protected override void Dispose(bool disposing)
 30ExpandedSubBlockStart.gifContractedSubBlock.gif        {
 31            if (disposing && (components != null))
 32ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 33                components.Dispose();
 34            }

 35            base.Dispose(disposing);
 36        }

 37
 38ContractedSubBlock.gifExpandedSubBlockStart.gif        Windows Form Designer generated code#region Windows Form Designer generated code
 39
 40ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary> 
 41        /// Required method for Designer support - do not modify 
 42        /// the contents of this method with the code editor. 
 43        /// </summary> 

 44        private void InitializeComponent()
 45ExpandedSubBlockStart.gifContractedSubBlock.gif        {
 46            this.components = new System.ComponentModel.Container();
 47            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TimeNotifier));
 48            this.Apply = new System.Windows.Forms.Button();
 49            this.btnCancel = new System.Windows.Forms.Button();
 50            this.gbSetting = new System.Windows.Forms.GroupBox();
 51            this.label1 = new System.Windows.Forms.Label();
 52            this.lblInfo = new System.Windows.Forms.Label();
 53            this.textBox1 = new System.Windows.Forms.TextBox();
 54            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
 55            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
 56            this.resetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 57            this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
 58            this.gbSetting.SuspendLayout();
 59            this.contextMenuStrip1.SuspendLayout();
 60            this.SuspendLayout();
 61            // 
 62            // Apply
 63            // 
 64            this.Apply.Location = new System.Drawing.Point(47173);
 65            this.Apply.Name = "Apply";
 66            this.Apply.Size = new System.Drawing.Size(7525);
 67            this.Apply.TabIndex = 1;
 68            this.Apply.Text = "OK";
 69            this.Apply.UseVisualStyleBackColor = true;
 70            // 
 71            // btnCancel
 72            // 
 73            this.btnCancel.Location = new System.Drawing.Point(151173);
 74            this.btnCancel.Name = "btnCancel";
 75            this.btnCancel.Size = new System.Drawing.Size(7525);
 76            this.btnCancel.TabIndex = 2;
 77            this.btnCancel.Text = "Cancel";
 78            this.btnCancel.UseVisualStyleBackColor = true;
 79            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
 80            // 
 81            // gbSetting
 82            // 
 83            this.gbSetting.Controls.Add(this.label1);
 84            this.gbSetting.Controls.Add(this.lblInfo);
 85            this.gbSetting.Controls.Add(this.textBox1);
 86            this.gbSetting.Location = new System.Drawing.Point(-22);
 87            this.gbSetting.Name = "gbSetting";
 88            this.gbSetting.Size = new System.Drawing.Size(27485);
 89            this.gbSetting.TabIndex = 4;
 90            this.gbSetting.TabStop = false;
 91            this.gbSetting.Text = "设置";
 92            // 
 93            // label1
 94            // 
 95            this.label1.AutoSize = true;
 96            this.label1.Location = new System.Drawing.Point(12452);
 97            this.label1.Name = "label1";
 98            this.label1.Size = new System.Drawing.Size(1913);
 99            this.label1.TabIndex = 6;
100            this.label1.Text = "";
101            // 
102            // lblInfo
103            // 
104            this.lblInfo.AutoSize = true;
105            this.lblInfo.Location = new System.Drawing.Point(4721);
106            this.lblInfo.Name = "lblInfo";
107            this.lblInfo.Size = new System.Drawing.Size(10013);
108            this.lblInfo.TabIndex = 5;
109            this.lblInfo.Text = "提醒间隔时间(秒):";
110            // 
111            // textBox1
112            // 
113            this.textBox1.Location = new System.Drawing.Point(4949);
114            this.textBox1.Name = "textBox1";
115            this.textBox1.Size = new System.Drawing.Size(6920);
116            this.textBox1.TabIndex = 4;
117            // 
118            // notifyIcon1
119            // 
120            this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
121            this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
122            this.notifyIcon1.Text = "定时提醒";
123            this.notifyIcon1.Visible = true;
124            this.notifyIcon1.DoubleClick += new System.EventHandler(this.resetToolStripMenuItem_Click);
125            // 
126            // contextMenuStrip1
127            // 
128ExpandedSubBlockStart.gifContractedSubBlock.gif            this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
129            this.resetToolStripMenuItem,
130            this.exitToolStripMenuItem}
);
131            this.contextMenuStrip1.Name = "contextMenuStrip1";
132            this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
133            this.contextMenuStrip1.Size = new System.Drawing.Size(15370);
134            // 
135            // resetToolStripMenuItem
136            // 
137            this.resetToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("resetToolStripMenuItem.Image")));
138            this.resetToolStripMenuItem.Name = "resetToolStripMenuItem";
139            this.resetToolStripMenuItem.Size = new System.Drawing.Size(15222);
140            this.resetToolStripMenuItem.Text = "Reset";
141            this.resetToolStripMenuItem.Click += new System.EventHandler(this.resetToolStripMenuItem_Click);
142            // 
143            // exitToolStripMenuItem
144            // 
145            this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
146            this.exitToolStripMenuItem.Size = new System.Drawing.Size(15222);
147            this.exitToolStripMenuItem.Text = "Exit";
148            this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
149            // 
150            // TimeNotifier
151            // 
152            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
153            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
154            this.ClientSize = new System.Drawing.Size(272224);
155            this.Controls.Add(this.gbSetting);
156            this.Controls.Add(this.btnCancel);
157            this.Controls.Add(this.Apply);
158            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
159            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
160            this.MinimizeBox = false;
161            this.Name = "TimeNotifier";
162            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
163            this.Text = "定时设置";
164            this.gbSetting.ResumeLayout(false);
165            this.gbSetting.PerformLayout();
166            this.contextMenuStrip1.ResumeLayout(false);
167            this.ResumeLayout(false);
168
169        }

170
171        
172
173        #endregion

174
175        private Button Apply;
176        private Button btnCancel;
177        private GroupBox gbSetting;
178        private Label lblInfo;
179        private TextBox textBox1;
180        private Label label1;
181        private NotifyIcon notifyIcon1;
182        private ContextMenuStrip contextMenuStrip1;
183        private ToolStripMenuItem exitToolStripMenuItem;
184        private ToolStripMenuItem resetToolStripMenuItem;
185
186    }

187}

188

 

 

 

转载于:https://www.cnblogs.com/shielin/archive/2008/11/28/1342888.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/463675.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Matrix Computations 1

matrix computation转载于:https://www.cnblogs.com/stoneresearch/archive/2012/06/05/4336290.html

Linux下修改只读文件

最近在linux Ubuntu下配置hadoop&#xff0c;遇到了一个只读文件core-site.xml&#xff0c;需要修改其中的内容&#xff0c;但是该文件是只读的。查了资料比较简单&#xff1a; chattr -i 文件 让只读文件可编辑 chattr i 文件 让文件只读 ubuntu下使用&#xff1a; sud…

动态dp模板题(树剖+dp+线段树)

动态最大带权独立集 &#xff08;还有一个是全局平衡二叉树的解法&#xff0c;还没学&#xff09; 1 #include"bits/stdc.h"2 3 using namespace std;4 const int inf 1e8;5 int n,m;6 int v[100005];7 const int nn 1e510;8 9 int link[nn<<1],son[nn<&l…

×××linux下vsftp服务器

一、编译安装vsftp [rootYYzs tmp]# tar -xvf vsftpd-2.2.0.tar.gz[rootYYzs tmp]# cd vsftpd-2.2.0[rootYYzs vsftpd-2.2.0]# make//vsftp默认配置中需要“nobody”用户&#xff0c;在系统中添加此用户[rootYYzs vsftpd-2.2.0]# useradd nobody//VSFTPD默认配置中需要“/usr/s…

WinCE程序的几种开发方法

文章允许转载,请注明出处和作者:luocq(akay_21cn_com)下面介绍的几种开发方法,还是倾向于Delphi的程序员,如果是熟练的VC程序员,当然VC是不二的选择.1、采用Delphi2007来进行WinCE .net程序开发http://spaces.msn.com/members/GordonLiWei/?partqsayear%3D2005%26amonth%3D12&…

几道Linux驱动相关面试题,你会几题?

1一、Linux基础1、任意3种网络操作的Linux命令,并说明他们的含义 1. ifconfig 命令ifconfig 用于查看和配置 Linux 系统的网络接口。 查看所有网络接口及其状态&#xff1a;ifconfig -a 。 使用 up 和 down 命令启动或停止某个接口&#xff1a;ifconfig eth0 up 和 ifconfig et…

解决Too many open files问题

转载&#xff1a;https://blog.csdn.net/zhuwinmin/article/details/72730288 当用linux做高并发服务器时&#xff0c;会遇到"Too many open files"的错误。 Linux是有文件句柄限制的&#xff08;open files&#xff09;&#xff0c;而且Linux默认不是很高&#xf…

RedHat Linux 5.5系统下配置yum包详细过程

1、挂载光盘 mount -t iso9660 /dev/dvd /mnt/cdrom2、建立文件夹 安装如下路径&#xff0c;建立对应的文件夹&#xff0c;其中pub文件夹需要创建4个。3、复制以下内容到指定文件夹 需要注意的是&#xff0c;如果按照第1步将光盘挂在到/mnt/cdrom 下面…

hadoop fs 基本命令

今天由于工作需要&#xff0c;需要使用到hadoop fs的一些命令&#xff0c;就简单的总结了下&#xff1a; 1&#xff0c;hadoop fs –fs [local | <file system URI>]&#xff1a;声明hadoop使用的文件系统&#xff0c;如果不声明的话&#xff0c;使用当前配置文件配置的…

树莓派的这十年

来源 | 新智元编辑 | 袁榭 好困刚刚过完10岁生日的树莓派&#xff0c;早已褪去了当年廉价电脑教具的外衣&#xff0c;一跃成为全球业界首屈一指的微型电脑品牌。为啥叫「Raspberry Pi」&#xff1f;从某种意义上讲&#xff0c;「树莓」这个命名方式其实很单纯&#xff0c;因为大…

存储过程入门与提高

什么是存储过程呢&#xff1f; 定义&#xff1a; 将常用的或很复杂的工作&#xff0c;预先用SQL语句写好并用一个指定的名称存储起来, 那么以后要叫数据库提供与已定义好的存储过程的功能相同的服务时,只需调用execute,即可自动完成命令。 讲到这里,可能有人要问&#xff1a;这…

C++ 11 nullptr关键字

C 11 nullptr关键字 转载&#xff1a;https://www.cnblogs.com/DswCnblog/p/5629073.html 熟悉C的童鞋都知道&#xff0c;为了避免“野指针”&#xff08;即指针在首次使用之前没有进行初始化&#xff09;的出现&#xff0c;我们声明一个指针后最好马上对其进行初始化操作。如…

Vue-watch选项

Vue ----watch 选项 用于 监听数据变化&#xff1a; 1 <!DOCTYPE html>2 <html lang"en">3 <head>4 <meta charset"UTF-8">5 <meta name"viewport" content"widthdevice-width, initial-scale1.0"…

对SqlServer2008中的日志进行截断的方法

--第一步、执行以下语句&#xff1a; USE 数据库名 GO --第二步、备份数据库日志到c:\1.bak中 BACKUP LOG 数据库名 to diskc:\1.bak GO --第三步、查询此数据库的逻辑文件名 DECLARE Log_FileName VARCHAR(256) SELECT Log_FileNamename FROM sys.database_files WHERE FILE_I…

layui 在springboot2.x 时,页面展示不了layui的问题

[[]]是thymeleaf的内联表达式&#xff0c;在script上加 th:inline"none" 即可 报错信息 转载于:https://www.cnblogs.com/SeaWxx/p/10287505.html

ArcGIS Flex API 中的 Flex 技术(一)--事件

作者&#xff1a;Flyingis 本文严禁用于商业目的&#xff0c;如需转载请注明作者及原文链接&#xff0c;其他疑问请联系&#xff1a;dev.vip#gmail.com 在ArcGIS Flex API中探索Flex使用是一种不错的学习方法&#xff0c;可以相互辅助理解ArcGIS Flex API和Flex&#…

C++11 bind注意事项(传引用参数的时候)

默认情况下&#xff0c;bind的那些不是占位符的参数被拷贝到bind返回的可调用对象中。 当需要把对象传到bind中的参数中时&#xff0c;需要使用ref或者cref。 例如&#xff1a;

四元數與旋轉

为什么80%的码农都做不了架构师&#xff1f;>>> 在討論「四元數」之前&#xff0c;我們來想想對三維直角座標而言&#xff0c;在物體旋轉會有何影響&#xff0c;可以擴充三維直角座標系統的旋轉為三角度系統&#xff08;Three-angle system&#xff09;&#xff0c…

玩一下数组

来源&#xff1a;嵌入式大杂烩数组是最基本的数据结构&#xff0c;关于数组的面试题也屡见不鲜&#xff0c;本文罗列了一些常见的面试题&#xff0c;仅供参考。目前有以下18道题目。数组求和求数组的最大值和最小值求数组的最大值和次大值求数组中出现次数超过一半的元素求数组…

https部署

准备证书及秘钥 方式一、springboot项目可直接在yml中配置 1、需要将证书转换成jks或p12格式&#xff0c;如 多个crt证书转为pem: cat xxx.crt xxx2.crt xxx3.xrt xxx4.crt > server.pempem证书转为jks&#xff1a; //PEM--->PFXopenssl pkcs12 -export -out test.pfx -…