Winform 调用Windows系统声音

核心代码

第一种声音

[DllImport("Kernel32.dll")] //引入命名空间 using System.Runtime.InteropServices;  
        public static extern bool Beep(int frequency, int duration);// 第一个参数是指频率的高低,越大越高,第二个参数是指响的时间多少

调用:

Beep(500, 700);

第二种声音 

 [DllImport("winmm.dll")]
public static extern bool PlaySound(String Filename, int Mod, int Flags);

调用:

PlaySound(@"C:\Windows\media\Windows Proximity Notification.wav", 0, 1); 

猜你喜欢

转载自blog.csdn.net/weixin_39237340/article/details/112976699