在c#中向exe添加通知声音文件

时间:2012-08-17 00:15:57

标签: c# embedded-resource resource-files

我正在尝试在用户按下按钮时添加通知警报

    private void button1_Click(object sender, EventArgs e)
    {
        SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\.........\ambbrdg7.wav");
        simpleSound.Play();
    }

我想将 ambbrdg7.wav 添加到我的exe文件中,以确保我的程序始终可以访问此文件

2 个答案:

答案 0 :(得分:10)

Project + Properties,Resources选项卡,单击“Add Resource”按钮上的箭头,然后选择.wav文件。然后就是:

var player = new System.Media.SoundPlayer();
player.Stream = Properties.Resources.tada;
player.Play();

其中“tada.wav”是我添加的资源,请将其更改为您的资源名称。

答案 1 :(得分:1)

您要么将文件添加为内容(将文件添加到项目中并将其设置为Build Action - > Content)或将其添加为资源 - 请参阅http://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.80).aspx