Beeping in C#

Environment: .NET, Visual Studio .NET, C#

This is part of a collection of C# programs that I wrote when I wanted to learn C# and .NET. I call these type of programs “Exploratory Programming.” They are all short applications that demonstrate some part of .NET and the forms interface that I couldn’t find in any book I had. All the programs are simple interactive examples.

I believe in auditory debugging when necessary, putting a sound in routines so you know they were entered but don’t have to sit in the debugger setting break points unless you have to. .NET doesn’t seem to have the equivalent of the WIN32 MessageBeep(nn) function. The following will enable it from C#:

using System.Runtime.InteropServices;           //reference
                                                //the name space
                                                //for use

public class Form1 : System.Windows.Forms.Form  //or whatever you
                                                //call the class
                                                //of your
                                                //application

{

[DllImport("user32.dll")]

public static extern boolMessageBeep(intSound);

Downloads

Not applicable

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read