Advertisement
Taximaniac

Updated Vesion of Joseph Bolens Christmas app

Dec 3rd, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.84 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. Option Strict On
  29.  
  30. Public Class DaysToChristmasForm
  31.  
  32. #Region " Class Level Constants and Variables"
  33.  
  34.     'Song File
  35.     Const SONG As String = "HereComesSantaClaus.mp3"
  36.  
  37.     'Define the song object - Edited by Christian Haugland - Taximaniac
  38.     Dim HereComesSantaClause As New AudioFile(SONG)
  39.  
  40.     Private GenerateRandom As Random = New Random(DateTime.Now.Millisecond) ' random seed
  41.  
  42. #End Region
  43.  
  44. #Region " Form Event Methods"
  45.  
  46.     Private Sub DaysToChristmasForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  47.         GetDays()
  48.         MyTimer.Interval = 500
  49.         MyTimer.Enabled = True
  50.         GetMusic()
  51.     End Sub
  52.  
  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.play()
  95.  
  96.             ' Edited by Christian Haugland -Taximaniac
  97.             ' We are using the AudioFile.vb class to play sound usin mci
  98.             ' so here we pause the song if it is not paused already
  99.             If HereComesSantaClause.IsPaused = False Then
  100.                 HereComesSantaClause.Pause()
  101.             End If
  102.         Else
  103.             'My.Computer.Audio.Play(SONG, AudioPlayMode.BackgroundLoop)
  104.             'MPlayer.Ctlcontrols.play()
  105.  
  106.             ' Edited by Christian Haugland -Taximaniac
  107.             ' We are using the AudioFile.vb class to play sound usin mci
  108.             ' so here we play the song if it is not playing already
  109.             If HereComesSantaClause.IsPaused = True Then
  110.                 HereComesSantaClause.Play()
  111.             End If
  112.         End If
  113.     End Sub
  114.  
  115. #End Region
  116.  
  117. #Region " Private Subroutines and Functions"
  118.  
  119.     ' Calculate days till Christmas and display in DaysToResultLabel
  120.     Private Sub GetDays()
  121.         Dim ChristmasYear As Integer = Today.Year
  122.         Dim ChristmasDate As New DateTime(ChristmasYear, 12, 25)
  123.  
  124.         If Today = ChristmasDate Then
  125.             DaysToLabel.Text = "Merry Christmas!"
  126.             DaysToResultLabel.Text = "0"
  127.             Exit Sub
  128.         End If
  129.  
  130.         If Today > ChristmasDate Then
  131.             ChristmasDate = ChristmasDate.AddYears(1)
  132.         End If
  133.  
  134.         Dim DaysTo As TimeSpan = ChristmasDate - Today
  135.         DaysToResultLabel.Text = DaysTo.Days.ToString
  136.  
  137.     End Sub
  138.  
  139.     ' Intialize the media player
  140.     Private Sub GetMusic()
  141.         'My.Computer.Audio.Play(song, AudioPlayMode.BackgroundLoop)
  142.         'With MPlayer
  143.         '    .Hide()
  144.         '    .settings.autoStart = True
  145.         '    .settings.setMode("Loop", True)
  146.         '    .URL = SONG
  147.         'End With
  148.  
  149.         ' Edited by Christian Haugland -Taximaniac
  150.         ' Just call the play function on the song object.
  151.         ' The object is declared on top in class level variables.
  152.         HereComesSantaClause.Play()
  153.     End Sub
  154.  
  155. #End Region
  156.  
  157.  
  158. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement