COMPUTER_LZY

要输就输给追求,要嫁就嫁给幸福

导航

C# Beep

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(
4000800);// Beep(800,300);
            }
        }

        
public void MessageBeepShow()
        {
            
for (int i = 0; i < 10; i++)
            {
                System.Threading.Thread.Sleep(
500);
                MessageBeep(MessageBeepType.Question);
            }
        }


    }

备注:console.Beep(4000800)其中4000是指发声的频率,800是发声时间!

posted on 2011-03-15 16:32  CANYOUNG  阅读(2484)  评论(0编辑  收藏  举报