Make a Beep

H

#Hai

Hi,
I want to throw out a series of 'beep..beep..beep' to the speaker. How to do
that ?
Thanks
 
M

Michael Giagnocavo [MVP]

You can also use P/Invoke to call Kernel32.dll!Beep.

It takes two arguments, the first one the frequency, and the second
one the duration and returns a bool for success.

Frequency must be from 37 to 32,767.

something like:

using System.Runtime.InteropServices;

public class whatever {
[DllImport("Kernel32.dll")]
public static extern bool Beep(UInt32 frequency, UInt32 duration);

public static void beepTime() {
Beep(1000, 300);
System.Threading.Thread.Sleep(300);
Beep(2000, 400);
System.Threading.Thread.Sleep(300);
Beep(500, 200);
System.Threading.Thread.Sleep(300);
}
}

-mike
MVP
 
N

Nicholas Paldino [.NET/C# MVP]

Hai,

The best way to do this would be to add a reference to
Microsoft.VisualBasic.dll and to call the static Beep method on the
Microsoft.VisualBasic.Interaction class.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top