Link to home
Start Free TrialLog in
Avatar of EEssam
EEssam

asked on

How can I play a small sound file when showing a form?

Hi,

I want to play a sound file when showing a form. The sound file contains a little ring just to notify the user about a new messages.

What would be the most efficient way to play the file?

Please advise.
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru 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
Avatar of EEssam
EEssam

ASKER

This is more suitable for me:

http://msdn2.microsoft.com/en-us/library/3w5b27z4(VS.80).aspx

But how can I add the sound file as a resource?
private void playSoundFromResource()
{
    SoundPlayer sndPing = new SoundPlayer(SoundRes.GetType(), "Ping.wav");
    sndPing.Play();
}

Open in new window

it is a little difficult in .net
First you have to create a .res file (Win32 resource file)
Insert the sound file there, it has to be "WAV" type
Go to your project settings, Application tab, and set your resource file.

To create and edit the .res file, you can create a Native Resource Template in your VS New File Wizard, add the wav file and save as a .res file