Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Beep using C#?

Status
Not open for further replies.

Kenny100

Technical User
Feb 6, 2001
72
NZ
Hi Folks

How do I make the PC system speaker beep using C#? I know this can be done with Visual Basic.Net using 'beep'.

I'd like to be able to perform a single beep and a double beep.

Cheers,
Kenny.
 
It seems you have to use the API. This
works for me:

public class MyBeep
{
[System.Runtime.InteropServices.DllImport("User32.Dll")]
private static extern int MessageBeep(Sounds uType);

public static void Beep()
{
MessageBeep(Sounds.MB_OK);
}
public static void Beep(Sounds s)
{
MessageBeep(s);
}

public enum Sounds : uint
{
MB_OK = 0,
MB_ICONHAND = 0x00000010,
MB_ICONQUESTION = 0x00000020,
MB_ICONEXCLAMATION = 0x00000030,
MB_ICONASTERISK = 0x00000040
}
}
 
Or you can use this...

[DllImport("kernel32.dll")]
public static extern bool Beep(int nFrequency, int nDuration);

Another option is to reference the Visual Basic runtime and add the following line:

Microsoft.VisualBasic.Interaction.Beep();

I hope that this helps! Neil Konitzer
Freisoft
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top