Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

18. Windows Forms Tips

18.15 How do I beep the computer's speaker in a Windows Form application?


There is no Windows Form function to beep your computer's speaker. But you can just invoke the Win32 API MessageBeep.

     using System.Runtime.InteropServices;
     ...
     
     [DllImport("user32.dll")]
     public static extern int MessageBeep(uint n);

     private void button2_Click(object sender, System.EventArgs e)
     {
          MessageBeep(0x0);
     }


Another method (suggested by msauper@sauper.com on microsoft.public.dotnet.framework.windowsforms)


Reference the VB.NET runtime support and just use the Beep() method.

The method is in:

Microsoft.Visual Basic.NET Runtime

The method is:

Microsoft.VisualBasic.Interaction.Beep();