【问题标题】:Add notification sound file to exe in c#在c#中将通知声音文件添加到exe
【发布时间】:2012-08-17 00:15:56
【问题描述】:

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

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

我想补充的 ambbrdg7.wav 以我的exe文件,以确保我的程序总是可以访问此文件 P>

【问题讨论】:

    标签: c# embedded-resource resource-files


    【解决方案1】:

    项目 + 属性,资源选项卡,单击“添加资源”按钮上的箭头并选择您的 .wav 文件。那么它就是:

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

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

    【讨论】:

      【解决方案2】:

      您要么希望将文件添加为内容(将文件添加到项目并将其设置为构建操作 -> 内容),要么将其添加为资源 - 请参阅 http://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.80).aspx

      【讨论】:

      • 如果您将其添加到您的项目并将其设置为内容,那么它应该与您的应用程序的路径相同,如果您将其添加为资源,您将使用msdn.microsoft.com/en-us/library/… 编辑:@Hans Passant 有资源的正确答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 2022-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多