1.前言:由於許多人使用電腦好長時間都不知道休息,我就是其中之一。我自從買了電腦之後,視力在不停的下降,身體也沒有原來好了。對此我十分擔心,為此我想到了自己做一個強制限制使用電腦時間,保護眼睛的小軟件。我是用vb.net實現的!
2.基本原理:
我是通過兩個Timer控件控制工作和休息時間,當工作時間過了之後。調用新窗口,新窗口是一個沒有邊框的全屏form並且不能關閉!只有你休息的時間過了窗體自動關閉,在過一段你工作的時間之後,電腦又將鎖定,強制保護你的眼睛,休息時間和工作時間可以自己設定!但是我建議工作50分鐘後,休息10分鐘!
3.部分代碼: Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Label5.Text = "系統當前時間:" & Now
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.MaskedTextBox1.Text <> "" And Me.MaskedTextBox2.Text <> "" Then
Me.Timer2.Enabled = True
Me.Timer2.Interval = CInt(Me.MaskedTextBox1.Text) * 1000 * 60
Me.Hide()
Else
MsgBox("請你輸入時間!")
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim peng As New Form2()
Me.Timer2.Enabled = False
Me.Visible = False
peng.Show()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Me.Hide()
e.Cancel = True
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MaskedTextBox1.Text = 50
Me.MaskedTextBox2.Text = 10
End Sub
End Class
Public Class Form2
Dim i As Long = 0
Dim flag As Boolean = True
Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If flag Then
e.Cancel = True
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Timer1.Interval = CLng(Form1.MaskedTextBox2.Text) * 1000 * 60
Me.ProgressBar1.Minimum = 0
Me.ProgressBar1.Maximum = CLng(Form1.MaskedTextBox2.Text) * 60
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Form1.Timer2.Enabled = True
Me.Close()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If i <= CInt(Form1.MaskedTextBox2.Text) * 60 Then
Me.Focus()
Me.TopMost = True
If i = CInt(Form1.MaskedTextBox2.Text) * 60 - 10 Then
flag = False
End If
Me.WindowState = FormWindowState.Maximized
i = i + 1
Me.ProgressBar1.Value = i
End If
End Sub
End Class
4.小結:這個軟件基本上實現了保護眼睛和身體的作用,可以阻止瘋狂的使用電腦而不休息。對於保護好自己的眼睛和身體有重要的作用!特色:打開後不能關閉。除非在任務管理器中結束進程!需要.NET Framework支持。強制保護你的身體!有好的身體才有好的明天!建議用1分鐘測試!