Export (0) Print
Expand All
10 out of 18 rated this helpful - Rate this topic

How to: Play a Sound from a Windows Form

This example plays a sound at a given path at run time.

private void playSimpleSound()
{
    SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");
    simpleSound.Play();
}

This example requires:

  • That you replace the file name "c:\Windows\Media\chimes.wav" with a valid file name.

  • (C#) A reference to the System.Media namespace.

File operations should be enclosed within appropriate structured exception handling blocks.

The following conditions may cause an exception:

Do not make decisions about the contents of the file based on the name of the file. For example, the file Form1.vb may not be a Visual Basic source file. Verify all inputs before using the data in your application.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.