100 likes | 216 Views
The SystemSounds Class. Includes five properties for making Windows operating system sounds: Asterisk Beep Exclamation Hand Question The Play() method is used to make the sound: SystemSounds.Beep.Play() Applications require the Imports System.Media statement. Playing Sound Files.
E N D
The SystemSounds Class • Includes five properties for making Windows operating system sounds:Asterisk Beep Exclamation Hand Question • The Play() method is used to make the sound:SystemSounds.Beep.Play() • Applications require the Imports System.Media statement. Visual Basic - Chapter 10
Playing Sound Files • Visual Basic applications can play Windows WAV audio files. • My.Computer.Audio object includes the Play() and Stop() methods for working with WAV files. • Audio files must be added to the Resources folder for an application to access them. • To add resource: Select menu Project | application Properties; select Resources tab, then Add Resource; browse to audio file • Reference to My.Resources. will then show file • Example playing audio in background: My.Computer.Audio.Play(My.Resources.Bird,AudioPlayMode.Background) Visual Basic - Chapter 10
The Timer Control • Located in Components folder in Toolbox • Properties include: • (Name) should begin with tmr. • Interval is the amount of time that passes before the Tick event procedure executes. • Enabled allows a Tick event to occur at the end of each interval. • Methods include Start() and Stop(). Visual Basic - Chapter 10
Demo: Timer Use a Timer object to alternate the color of a form between red and blue. Experiment with varying Interval values to slow down or speed up the alternating colors. Visual Basic - Chapter 10
Demo: Timer Code for Timer application. Private Sub tmrTimer_Tick() If Me.BackColor = Color.Red Then Me.BackColor = Color.Blue Else Me.BackColor = Color.Red End If End Sub Private Sub Form1_Load() Me.BackColor = Color.Red End Sub Private Sub cmdQuit_Click() Application.Exit() End Sub Experiment with varying Interval values to slow down or speed up the alternating colors. Visual Basic - Chapter 10
Simple Animation • Timers are used to create simple animations • Multiple images are placed on the form, each on top of the others (same size, same place, but with different “phases” in the image) • At any given time, one image is Visible, the others are not • Each time the Timer fires, the visible image changes, rotating through the “phases” • Similar to flipping the corners of the pages in a minibook with “moving images” in the corner Visual Basic - Chapter 10
Simple Animation - Wink • In Paint, create a Smiley face (be sure to crop tight around the face) -> smiley.bmp [open smiley.wmf] • Copy it and erase part of right eye -> smiley2.bmp • Create VB Form with 2 picture boxes overlaid on each other, with smiley visible, smiley2 not visible • Add a timer with Tick event that reverses which image is visible Visual Basic - Chapter 10
Exercise 10-12: TurtleRun Simulate a turtle running by cycling through 3 graphics of a turtle in various stages of walking. Set the timer Interval property to different values in the speed buttons. Visual Basic - Chapter 10
Exercise 10-12: TurtleRun - Code Partial code for TurtleRun is shown below: Option Explicit Private intCycle As Integer Private Sub Form1_Load() intCycle = 1 Me.picTurtle1.Visible = True Me.picTurtle2.Visible = False Me.picTurtle3.Visible = False End Sub Private Sub tmrTurtle_Tick() If intCycle = 1 Then Me.picTurtle1.Visible = True Me.picTurtle2.Visible = False Me.picTurtle3.Visible = False intCycle = 2 ElseIf intCycle = 2 Then Me.picTurtle1.Visible = False Me.picTurtle2.Visible = True Me.picTurtle3.Visible = False intCycle = 3 ElseIf intCycle = 3 Then Me.picTurtle1.Visible = False Me.picTurtle2.Visible = False Me.picTurtle3.Visible = True intCycle = 1 End If End Sub Visual Basic - Chapter 10
Exercise 10-15: Bird Flying Simulate a bird flying by cycling through flying graphics. Visual Basic - Chapter 10