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


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.
Who is Participating?
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
have a look to this little tutorial:

you will need the namespace System.Media
EEssamAuthor Commented:
This is more suitable for me:

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

Open in new window

Jaime OlivaresSoftware ArchitectCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.