C#/VB.NET Play System Sound

In order to play one of the system sounds from your C#/VB .NET you can use the ready to use system sounds the Windows uses for common tasks. Basically, there are 5 sounds that Windows presents:

  1. Asterisk
  2. Beep
  3. Exclamation
  4. Hand
  5. Question

Here is a snap example of filling the system sounds to a combo box and play one of them when an item is selected:


        private void Form1_Load(object sender, EventArgs e)
        {

            comboBox1.DisplayMember = "Text";
            comboBox1.ValueMember = "Value";

            var systemSounds = new[]
            {
                new { Text = "Asterisk", Value = System.Media.SystemSounds.Asterisk },
                new { Text = "Beep", Value = System.Media.SystemSounds.Beep },
                new { Text = "Exclamation", Value = System.Media.SystemSounds.Exclamation },
                new { Text = "Hand", Value = System.Media.SystemSounds.Hand },
                new { Text = "Question", Value = System.Media.SystemSounds.Question }
            };

            comboBox1.DataSource = systemSounds;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ((System.Media.SystemSound)comboBox1.SelectedValue).Play();
        }

That’s it 🙂

Please note, by default most of the sounds are the same, and you can change them in the System Sounds Properties in the Control Panel.

Relevant Links:

SystemSounds Class
https://docs.microsoft.com/en-us/dotnet/api/system.media.systemsounds?view=dotnet-plat-ext-3.1

More advanced example of using the Windows System Sounds
https://www.codeproject.com/Articles/2740/Play-Windows-sound-events-defined-in-system-Contro

Microncode Components and Libraries:
https://microncode.com/developers/

Leave a Reply