EyeTimer - reduce eye strain-VBForums
Results 1 to 1 of 1

Thread: EyeTimer - reduce eye strain

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    20

    Cool EyeTimer - reduce eye strain

    Now that my job is looking at a computer screen most of the day, my eyesight has gotten noticeably worse due to eye strain. Someone told me about the "20/20/20 rule" to reduce eye strain: every 20 minutes, look at something 20 feet away for 20 seconds. It makes a difference over time, but it's tough to remember.

    I built this timer to remind me. I'm pretty new to VB, so you guys will probably find many ways to improve this. Please feel free to customize.

    Code:
    Public Class Form1
        Dim ToggleF9 As Boolean = False
        Sub Form1Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Me.Height = 132
            Me.KeyPreview = True
            NotifyIcon1.Visible = True
        End Sub
        Private Sub FormBorderTog(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
            If (e.KeyCode = Keys.F9) Then
                ' When F9 is pressed, switch boolean value
                Call Toggle()
            End If
            If ToggleF9 = True Then
                'toggle form border on/off according to boolean value
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
                If Timer1.Enabled = True Then
                    Me.Height = 200
                Else
                    Me.Height = 170
                End If
            Else
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
                If Timer1.Enabled = True Then
                    Me.Height = 162
                Else
                    Me.Height = 132
                End If
            End If
        End Sub
        Private Sub Toggle()
            'toggle boolean value
            If ToggleF9 = False Then
                ToggleF9 = True
            Else
                ToggleF9 = False
            End If
        End Sub
        Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click
            'show progress bar in form when timer is running
            Timer1.Enabled = True
            If Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle Then
                Me.Height = 200
            Else
                Me.Height = 162
            End If
    
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            'increments progress bar until full, then triggers message or beep
            ProgressBar1.PerformStep()
            Timer1.Enabled = False
            Timer1.Dispose()
            If ProgressBar1.Value = ProgressBar1.Maximum Then
                My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
                If CheckBox1.Checked = False Then
                    'click to reset
                    MsgBox("Look at something at least 20 feet away for at least 20 seconds.", MsgBoxStyle.MsgBoxSetForeground, "EyeTimer")
                    ProgressBar1.Value = 0
                    Timer1.Enabled = True
                Else
                    '20 second delay for auto-reset
                    NotifyIcon1.ShowBalloonTip(20000, "EyeTimer Notification", "Look at something 20 feet away for 20 seconds.", ToolTipIcon.None)
                    Timer2.Enabled = True
                End If
            Else
                Timer1.Enabled = True
            End If
        End Sub
    
        Private Sub ButtonStop_Click(sender As Object, e As EventArgs) Handles ButtonStop.Click
            'stop and reset timer, hide progress bar
            Timer1.Enabled = False
            Timer1.Dispose()
            ProgressBar1.Value = 0
            If Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle Then
                Me.Height = 170
            Else
                Me.Height = 132
            End If
    
        End Sub
    
        Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
            '20 second delay before auto-reset
            Timer2.Enabled = False
            Timer2.Dispose()
            ProgressBar1.Value = 0
            Timer1.Enabled = True
        End Sub
    End Class
    About half the code here relates to showing/hiding the form border, and resizing; this can easily be removed. This was just to confound my coworker so he couldn't figure out how to close my application when I leave it running.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.