日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2023/12/18 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 保护视力,我写的一个定时提醒的小玩意。 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


做程序員2年了,感覺視力越來越差。有時候常常工作到忘記休息。于是就想寫一個能夠定時提醒的小東西(公司不讓從網絡下載別的程序)。
功能:
??? 1.能夠每隔一段時間提醒我休息,做做眼保健操。
??? 2.能夠自己設定時間間隔.
???
運行環(huán)境:.net framework 2.0

使用說明:
雙擊托盤 重新設定。
右鍵托盤 可以推出程序。
主界面如圖,

?

能夠設定提醒的時間間隔,以秒記,我一般設置為1800,半個小時,默認為半個小時。
設定后點擊ok,關閉主窗口,任務欄會有個托盤。

實現(xiàn)原理:

啟動一個新線程,讓其sleep所設置的時間間隔的長度,然后彈出對話框。

?

?

下面是代碼文件:只有一個類TimeNotifier

有三個PartialClass? TimeNotifier.cs, ?TimeNotifier.event.cs,TimeNotifier.Designer.cs

?

TimeNotifier.cs

?

Code
?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
10{
11????public?partial?class?TimeNotifier?:?Form
12????{
13????????/**////?<summary>
14????????///?Const
15????????///?</summary>

16????????public?class?ConstDefs
17????????{
18????????????internal?static?int?DefaultSlot?=?1800;
19????????????internal?static?int?OneThousant?=?1000;
20????????}

21
22????????/**////?<summary>
23????????///?Constructor
24????????///?</summary>

25????????public?TimeNotifier()
26????????{
27????????????InitializeComponent();
28????????????SetDefault();
29????????????RegisterEvent();
30????????????TimeReminder();
31????????}

32
33????????/**////?<summary>
34????????///?Exit
35????????///?</summary>
36????????///?<param?name="sender"></param>
37????????///?<param?name="e"></param>

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

43
44????????/**////?<summary>
45????????///?Reset
46????????///?</summary>
47????????///?<param?name="sender"></param>
48????????///?<param?name="e"></param>

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

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

58????}

59}

?

TimeNotifier.event.cs

?

Code
?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
10{
11????public?partial?class?TimeNotifier
12????{
13????????/**////?<summary>
14????????///?注冊事件.
15????????///?</summary>

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

21
22????????/**////?<summary>
23????????///?Closing
24????????///?</summary>
25????????///?<param?name="sender"></param>
26????????///?<param?name="e"></param>

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

32
33????????/**////?<summary>
34????????///?Reset
35????????///?</summary>
36????????///?<param?name="sender"></param>
37????????///?<param?name="e"></param>

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

44
45
46????????/**////?<summary>?
47????????///?Set?Tray?
48????????///?</summary>?

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

54
55????????/**////?<summary>
56????????///?啟動新線程.
57????????///?</summary>

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

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

67
68????????private?void?TimeNotice()
69????????{
70????????????while?(true)
71????????????{
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

Code
??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
?11{
?12????public?partial?class?TimeNotifier
?13????{
?14????????/**////?<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
?25????????/**////?<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)
?30????????{
?31????????????if?(disposing?&&?(components?!=?null))
?32????????????{
?33????????????????components.Dispose();
?34????????????}

?35????????????base.Dispose(disposing);
?36????????}

?37
?38????????Windows?Form?Designer?generated?code#region?Windows?Form?Designer?generated?code
?39
?40????????/**////?<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()
?45????????{
?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(47,?173);
?65????????????this.Apply.Name?=?"Apply";
?66????????????this.Apply.Size?=?new?System.Drawing.Size(75,?25);
?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(151,?173);
?74????????????this.btnCancel.Name?=?"btnCancel";
?75????????????this.btnCancel.Size?=?new?System.Drawing.Size(75,?25);
?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(-2,?2);
?87????????????this.gbSetting.Name?=?"gbSetting";
?88????????????this.gbSetting.Size?=?new?System.Drawing.Size(274,?85);
?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(124,?52);
?97????????????this.label1.Name?=?"label1";
?98????????????this.label1.Size?=?new?System.Drawing.Size(19,?13);
?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(47,?21);
106????????????this.lblInfo.Name?=?"lblInfo";
107????????????this.lblInfo.Size?=?new?System.Drawing.Size(100,?13);
108????????????this.lblInfo.TabIndex?=?5;
109????????????this.lblInfo.Text?=?"提醒間隔時間(秒):";
110????????????//?
111????????????//?textBox1
112????????????//?
113????????????this.textBox1.Location?=?new?System.Drawing.Point(49,?49);
114????????????this.textBox1.Name?=?"textBox1";
115????????????this.textBox1.Size?=?new?System.Drawing.Size(69,?20);
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????????????//?
128????????????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(153,?70);
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(152,?22);
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(152,?22);
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(272,?224);
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

總結

以上是生活随笔為你收集整理的保护视力,我写的一个定时提醒的小玩意。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。