JayBeeOH

DaysToChristmas

Nov 30th, 2014
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.92 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2014. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   DaysToChristmas
  13. ' Author:         Joseph L. Bolen
  14. ' Date Created:   Nov 2014
  15. '
  16. 'Description:     Uses the Timer, PictureBoxes, Labels and Media Player to
  17. '                 create a festive countdown to Christmas.
  18. '                 NOTE: When using the Media Player, a reference must be added to project
  19. '                 and added to the toolbox.  My.Computer.Audio code only good for Wav files of
  20. '                 a PCM type. While wav files are large, using the My.Computer.Audio approach
  21. '                 does not require the user to have Windows Media Player installed.
  22. '
  23. '                 Documentation is at:
  24. '                   App's screen image is at: http://imgur.com/idy79Mz
  25. '                   App's Visual Basic .NET code is at http://pastebin.com/BithLrR7
  26. '                   Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
  27. '-------------------------------------------------------------------------------------------
  28.  
  29. Option Strict On
  30.  
  31. Public Class DaysToChristmasForm
  32.  
  33. #Region " Class Level Constants and Variables"
  34.  
  35.     Const SONG As String = "HereComesSantaClaus.mp3"
  36.     Private GenerateRandom As Random = New Random(DateTime.Now.Millisecond) ' random seed
  37.  
  38. #End Region
  39.  
  40. #Region " Form Event Methods"
  41.  
  42.     ' Housekeeping and Initialization.
  43.     Private Sub DaysToChristmasForm_Load(sender As Object, e As EventArgs) _
  44.         Handles Me.Load
  45.  
  46.         GetDays()
  47.         MyTimer.Interval = 500
  48.         MyTimer.Enabled = True
  49.         GetMusic()
  50.     End Sub
  51.  
  52.     ' Add snow.
  53.     Private Sub DaysToChristmasForm_Paint(sender As Object, e As PaintEventArgs) _
  54.         Handles Me.Paint
  55.  
  56.         Dim whitePen As New Pen(Color.White, 2)
  57.         Dim xInteger As Integer
  58.         Dim yInteger As Integer
  59.         For index As Integer = 1 To 300
  60.             xInteger = GenerateRandom.Next(1, Me.Width)
  61.             yInteger = GenerateRandom.Next(1, Me.Height)
  62.             e.Graphics.DrawLine(whitePen, xInteger, yInteger,
  63.                                 xInteger + 1, yInteger + 1)
  64.         Next
  65.     End Sub
  66.  
  67. #End Region
  68.  
  69. #Region " Control Event Methods"
  70.  
  71.     ' Use the Timer tick event to move PictureBox arross the screen.
  72.     Private Sub MyTimer_Tick(sender As Object, e As EventArgs) _
  73.         Handles MyTimer.Tick
  74.  
  75.         Static xLocation As Integer = MovingPictureBox.Left
  76.  
  77.         ' Set new X coordinate
  78.         xLocation -= 10 'move right to left
  79.         ' Graphic off edge of the form; reset it
  80.         If xLocation <= -MovingPictureBox.Width Then
  81.             xLocation = Me.Width
  82.         End If
  83.         ' Move image
  84.         MovingPictureBox.SetBounds(xLocation, MovingPictureBox.Top,
  85.                                    MovingPictureBox.Width, MovingPictureBox.Height)
  86.     End Sub
  87.  
  88.     ' Toggle sound.
  89.     Private Sub MuteCheckBox_CheckedChanged(sender As Object, e As EventArgs) _
  90.         Handles MuteCheckBox.CheckedChanged
  91.  
  92.         If MuteCheckBox.Checked = True Then
  93.             'My.Computer.Audio.Stop()
  94.             MPlayer.Ctlcontrols.pause()
  95.         Else
  96.             'My.Computer.Audio.Play(SONG, AudioPlayMode.BackgroundLoop)
  97.             MPlayer.Ctlcontrols.play()
  98.         End If
  99.     End Sub
  100.  
  101. #End Region
  102.  
  103. #Region " Private Subroutines and Functions"
  104.  
  105.     ' Calculate days till Christmas and display in DaysToResultLabel
  106.     Private Sub GetDays()
  107.         Dim ChristmasYear As Integer = Today.Year
  108.         Dim ChristmasDate As New DateTime(ChristmasYear, 12, 25)
  109.  
  110.         If Today = ChristmasDate Then
  111.             DaysToLabel.Text = "Merry Christmas!"
  112.             DaysToResultLabel.Text = "0"
  113.             Exit Sub
  114.         End If
  115.  
  116.         If Today > ChristmasDate Then
  117.             ChristmasDate = ChristmasDate.AddYears(1)
  118.         End If
  119.  
  120.         Dim DaysTo As TimeSpan = ChristmasDate - Today
  121.         DaysToResultLabel.Text = DaysTo.Days.ToString
  122.  
  123.     End Sub
  124.  
  125.     ' Intialize the media player
  126.     Private Sub GetMusic()
  127.         'My.Computer.Audio.Play(song, AudioPlayMode.BackgroundLoop)
  128.         With MPlayer
  129.             .Hide()
  130.             .settings.autoStart = True
  131.             .settings.setMode("Loop", True)
  132.             .URL = SONG
  133.         End With
  134.     End Sub
  135.  
  136. #End Region
  137.  
  138. End Class
Advertisement
Add Comment
Please, Sign In to add comment