C#让电脑发出声音
C#让电脑发出嗡鸣声
代码:
C# 全选
using System.Runtime.InteropServices;
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 发出嗡鸣声
/// 引入命名空间 using System.Runtime.InteropServices;
/// </summary>
/// <param name="frequency">声音频率</param>
/// <param name="duration">声音持续时间</param>
/// <returns></returns>
[DllImport("Kernel32.dll")]
public static extern bool Beep(int frequency, int duration);
private void button1_Click(object sender, EventArgs e)
{
Beep(int.Parse(txt_frequency.Text), int.Parse(txt_duration.Text));
}
}
}
播放WAV文件
C# 全选
[DllImport("winmm.dll")]
public static extern bool PlaySound(String Filename, int Mod, int Flags);
PlaySound(@"C:\Windows\media\Windows Proximity Notification.wav", 0, 1);
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post 张国生