Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I code my WinForms application play a system sound?

For C++ there is a function, PlaySound, that can be used to, uh, play sounds. Is there something like this for C#? I have an application that I want to play a system sound when it starts, to annunciate its initiation.

There has GOT to be a way. I hope.

I want to put this at the end of my Form_Load event:

private void Form1_Load(object sender, EventArgs e)
{
    /* 
       A bunch of configuration and initialization stuff
    */

    PlayBeepBoop();
}

private void PlayBeepBoop()
{
    PlaySystemSound("Beep");
}
like image 820
Cyberherbalist Avatar asked May 13 '14 23:05

Cyberherbalist


1 Answers

There's a SystemSounds class that sounds like what you might want:

SystemSounds.Beep.Play();

It corresponds to whatever "wav" file you have set as the "Default Beep" in Windows' sound settings.

like image 160
Grant Winney Avatar answered Oct 01 '22 19:10

Grant Winney