Link to home
Start Free TrialLog in
Avatar of HawaiiDragon
HawaiiDragon

asked on

Playing a sound on a button click in a windows program C#

Hi all:
 Im trying to play a spcific sound on a button click. I have tried creating a method to do so but its not working. Any help would be great.
Avatar of ToddBeaulieu
ToddBeaulieu
Flag of United States of America image

huh. I've never tried this in .net!

Does this help?

http://www.eggheadcafe.com/articles/20030302.asp
Avatar of HawaiiDragon
HawaiiDragon

ASKER

not really....  unfortunaly
it works in his soluition but not mine.... quite annoying
Avatar of Mike Tomlinson
Assuming the wav file is in the same folder as your EXE:

        private void button1_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer sp = new System.Media.SoundPlayer("yeehaw.wav");
            sp.Play();
        }

See SoundPlayer():
http://msdn.microsoft.com/en-us/library/system.media.soundplayer(VS.80).aspx
okay how do I add the sound clip "whip.wav" as a resource becasue I still cant get it to work.
please see the doc file for full details. Let me know what ive done wrong I feel like such an idiot.

problems.doc
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your a god. Now my question is why did this work and not the others. Is it because I did not make it an embedded resource? Anything I can learn is appriciated.
With my previous submission, the wav file would have to be physically located in the same folder as the running .net exe.  As an embedded resource it is contained within the EXE and always there.