A timer to shut down Windows

well if you have a teenage daughter, it can get to the point where you want to block myspace access after a certain of night. Otherwise they will spend hours on there. In addition, you want to make sure your kids are not on the computer all hours of the night. So the posts over the next couple of days will deal with this that I am working on. What I decided to do, was create a windows service that contained a timer that 15 minutes before 11PM a countdown form would appear. The code below would contain the concepts to count down backwards from 15 minutes.

Private Function ConvertSecondstoCountdownTime(ByVal Seconds As Integer) _
                           As String

        Dim Result As String
        Dim Minutes As Integer
        Dim RemainingSeconds As Integer

        If Seconds < 60 Then
            Result = Seconds.ToString

        Else

            Minutes = Seconds \ 60

            RemainingSeconds = Seconds – (Minutes * 60)

            If RemainingSeconds < 10 Then
                Result = String.Format("{0:G}:0{1:G}", Minutes, _
                                        RemainingSeconds)
            Else
                Result = String.Format("{0:G}:{1:G}", Minutes, _
                                        RemainingSeconds)

            End If

        End If

        Return Result

    End Function

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        timCount = timCount + 1
        Dim Result As String
        Dim Minutes As Integer
        Dim RemainingSeconds As Integer
        Dim ts As New TimeSpan(CLng((timCount) * 10000000))

        Label2.Text = Me.ConvertSecondstoCountdownTime((900 – timCount))

       If Label2.Text.IndexOf("00") > -1 Then
            ProgressBar1.Value = ProgressBar1.Value + 1
        End If
       
        If timCount >= 900 Then
            MsgBox("Your Time Has Been Reached")
            Timer1.Enabled = False
            timCount = 0
            ProgressBar1.Value = 0
        End If

    End Sub

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: