Welcome to Dream.In.Code
Become a VB Expert!

Join 137,268 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,476 people online right now. Registration is fast and FREE... Join Now!




Adding Sound to a click event..

 
Reply to this topicStart new topic

Adding Sound to a click event.., play a wav or mp3 or whatever when u click a button, label, etc

CanadaRules
11 Dec, 2006 - 05:50 PM
Post #1

New D.I.C Head
*

Joined: 15 Nov, 2006
Posts: 10


My Contributions
ok i knwo your suppoed to write code example but i dont knwo where i need to start. Ive posted on here before for Homework and stuff but this is for personal use here.......

im making a match game for a little kid in my family where u flipover cards and try to match them and well you know how that game works......

but depending on whether they get a match or not i want the program to play a certain souund file if they get a match and a certian sound file if they do not get a match.

I needed to know how to activate a souind file when a CLICK EVENT happens.

Any help or hints would be greatly appreciated.


Thanks!!! cool.gif

This post has been edited by CanadaRules: 11 Dec, 2006 - 05:50 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Adding Sound To A Click Event..
11 Dec, 2006 - 07:13 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You need to add a windows media player component to your form. Set its Visible property to false, so it won't show up. Then inside the click event of your button/object play the file that has the sound you want to play.

Here is a little tutorial to get you started.
User is offlineProfile CardPM
+Quote Post

the_hangman
RE: Adding Sound To A Click Event..
12 Dec, 2006 - 06:02 AM
Post #3

D.I.C Addict
Group Icon

Joined: 18 Jan, 2006
Posts: 593



Thanked: 1 times
Dream Kudos: 200
My Contributions
assuming you are using Visual Basic 2005 you could use
My.Computer.Audio.Play("file to play here", playmodehere)

"file to play here" is the link to the sound file (i recommend you import it as a resource and use that)

you don't have to use a play mode, but your choices are
- Background = this plays the sound in the background while you are doing other stuff
- BackgroundLoop = this plays the sound over and over and over in the background while you are doing other stuff
- WaitToComplete = plays the sound, but pauses the application so that you can't do anything until the sound is done playing (the one you will most likely want in your case)
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 07:40PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month