Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2014. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: DaysToChristmas
- ' Author: Joseph L. Bolen
- ' Date Created: Nov 2014
- '
- 'Description: Uses the Timer, PictureBoxes, Labels and Media Player to
- ' create a festive countdown to Christmas.
- ' NOTE: When using the Media Player, a reference must be added to project
- ' and added to the toolbox. My.Computer.Audio code only good for Wav files of
- ' a PCM type. While wav files are large, using the My.Computer.Audio approach
- ' does not require the user to have Windows Media Player installed.
- '
- ' Documentation is at:
- ' App's screen image is at: http://imgur.com/idy79Mz
- ' App's Visual Basic .NET code is at http://pastebin.com/BithLrR7
- ' Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
- '-------------------------------------------------------------------------------------------
- Option Strict On
- Public Class DaysToChristmasForm
- #Region " Class Level Constants and Variables"
- 'Song File
- Const SONG As String = "HereComesSantaClaus.mp3"
- 'Define the song object - Edited by Christian Haugland - Taximaniac
- Dim HereComesSantaClause As New AudioFile(SONG)
- Private GenerateRandom As Random = New Random(DateTime.Now.Millisecond) ' random seed
- #End Region
- #Region " Form Event Methods"
- Private Sub DaysToChristmasForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- GetDays()
- MyTimer.Interval = 500
- MyTimer.Enabled = True
- GetMusic()
- End Sub
- Private Sub DaysToChristmasForm_Paint(sender As Object, e As PaintEventArgs) _
- Handles Me.Paint
- Dim whitePen As New Pen(Color.White, 2)
- Dim xInteger As Integer
- Dim yInteger As Integer
- For index As Integer = 1 To 300
- xInteger = GenerateRandom.Next(1, Me.Width)
- yInteger = GenerateRandom.Next(1, Me.Height)
- e.Graphics.DrawLine(whitePen, xInteger, yInteger,
- xInteger + 1, yInteger + 1)
- Next
- End Sub
- #End Region
- #Region " Control Event Methods"
- ' Use the Timer tick event to move PictureBox arross the screen.
- Private Sub MyTimer_Tick(sender As Object, e As EventArgs) _
- Handles MyTimer.Tick
- Static xLocation As Integer = MovingPictureBox.Left
- ' Set new X coordinate
- xLocation -= 10 'move right to left
- ' Graphic off edge of the form; reset it
- If xLocation <= -MovingPictureBox.Width Then
- xLocation = Me.Width
- End If
- ' Move image
- MovingPictureBox.SetBounds(xLocation, MovingPictureBox.Top,
- MovingPictureBox.Width, MovingPictureBox.Height)
- End Sub
- ' Toggle sound.
- Private Sub MuteCheckBox_CheckedChanged(sender As Object, e As EventArgs) _
- Handles MuteCheckBox.CheckedChanged
- If MuteCheckBox.Checked = True Then
- 'My.Computer.Audio.Stop()
- 'MPlayer.Ctlcontrols.play()
- ' Edited by Christian Haugland -Taximaniac
- ' We are using the AudioFile.vb class to play sound usin mci
- ' so here we pause the song if it is not paused already
- If HereComesSantaClause.IsPaused = False Then
- HereComesSantaClause.Pause()
- End If
- Else
- 'My.Computer.Audio.Play(SONG, AudioPlayMode.BackgroundLoop)
- 'MPlayer.Ctlcontrols.play()
- ' Edited by Christian Haugland -Taximaniac
- ' We are using the AudioFile.vb class to play sound usin mci
- ' so here we play the song if it is not playing already
- If HereComesSantaClause.IsPaused = True Then
- HereComesSantaClause.Play()
- End If
- End If
- End Sub
- #End Region
- #Region " Private Subroutines and Functions"
- ' Calculate days till Christmas and display in DaysToResultLabel
- Private Sub GetDays()
- Dim ChristmasYear As Integer = Today.Year
- Dim ChristmasDate As New DateTime(ChristmasYear, 12, 25)
- If Today = ChristmasDate Then
- DaysToLabel.Text = "Merry Christmas!"
- DaysToResultLabel.Text = "0"
- Exit Sub
- End If
- If Today > ChristmasDate Then
- ChristmasDate = ChristmasDate.AddYears(1)
- End If
- Dim DaysTo As TimeSpan = ChristmasDate - Today
- DaysToResultLabel.Text = DaysTo.Days.ToString
- End Sub
- ' Intialize the media player
- Private Sub GetMusic()
- 'My.Computer.Audio.Play(song, AudioPlayMode.BackgroundLoop)
- 'With MPlayer
- ' .Hide()
- ' .settings.autoStart = True
- ' .settings.setMode("Loop", True)
- ' .URL = SONG
- 'End With
- ' Edited by Christian Haugland -Taximaniac
- ' Just call the play function on the song object.
- ' The object is declared on top in class level variables.
- HereComesSantaClause.Play()
- End Sub
- #End Region
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement