Aug 18, 2002 #1 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.
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.
Aug 19, 2002 #2 JCARPENTER Programmer Mar 30, 2000 8 US 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 } } Upvote 0 Downvote
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 } }
Aug 19, 2002 #3 neilkonitzer Programmer Jun 27, 2001 168 US 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 http://www.freisoft.com Upvote 0 Downvote
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 http://www.freisoft.com