C# Beep
时间:2011-03-15 来源:MISS_MY_GOD
public class myBeep
{
[DllImport("kernal32.dll")]
public static extern bool Beep(int freq, int duration);
public enum MessageBeepType
{
Default = -1,
Ok = 0x00000000,
Error = 0x00000010,
Question = 0x00000020,
Warning = 0x00000030,
Information = 0x00000040
}
[DllImport("user32.dll", SetLastError = true)]
public static extern bool MessageBeep(MessageBeepType type);
public void BeepShow()
{
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
Console.Beep(4000, 800);// Beep(800,300);
}
}
public void MessageBeepShow()
{
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
MessageBeep(MessageBeepType.Question);
}
}
}
{
[DllImport("kernal32.dll")]
public static extern bool Beep(int freq, int duration);
public enum MessageBeepType
{
Default = -1,
Ok = 0x00000000,
Error = 0x00000010,
Question = 0x00000020,
Warning = 0x00000030,
Information = 0x00000040
}
[DllImport("user32.dll", SetLastError = true)]
public static extern bool MessageBeep(MessageBeepType type);
public void BeepShow()
{
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
Console.Beep(4000, 800);// Beep(800,300);
}
}
public void MessageBeepShow()
{
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(500);
MessageBeep(MessageBeepType.Question);
}
}
}
备注:console.Beep(4000, 800)其中4000是指发声的频率,800是发声时间!
相关阅读 更多 +