[英]Add notification sound file to exe in c#
I'm trying to add a notification alarm when a user presses a button 我正在尝试在用户按下按钮时添加通知警报
private void button1_Click(object sender, EventArgs e)
{
SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\.........\ambbrdg7.wav");
simpleSound.Play();
}
I want to add the ambbrdg7.wav to my exe file to make sure my program always has access to this file 我想将ambbrdg7.wav添加到我的exe文件中,以确保我的程序始终可以访问此文件
Project + Properties, Resources tab, click on the arrow on the "Add Resource" button and select your .wav file. 单击项目+属性,资源选项卡,单击“添加资源”按钮上的箭头,然后选择.wav文件。 Then it is simply:
那就简单地说:
var player = new System.Media.SoundPlayer();
player.Stream = Properties.Resources.tada;
player.Play();
where "tada.wav" was the resource I added, change it to your resource name. “tada.wav”是我添加的资源,将其更改为您的资源名称。
您要么将文件添加为内容(将文件添加到项目中并将其设置为Build Action - > Content)或将其添加为资源 - 请参阅http://msdn.microsoft.com/en-us/library/ 7k989cfy(v = VS.80)的.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.