Winforms 如何使用组合框更改windows窗体应用程序的声音文件?

Winforms 如何使用组合框更改windows窗体应用程序的声音文件?,winforms,Winforms,我正在开发一个Windows窗体应用程序。目前,我正在为我的windows窗体应用程序进行设置方面的工作。在设置窗体上,我可以切换我的应用程序的提示音。默认的声音代码如下所示 public String defaultAlertTone = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sounds\\applause-2.wav"; 至于设置,我已经包括了2个默认音调供用户通过组合框选择。组合框的代码如下所示 private

我正在开发一个Windows窗体应用程序。目前,我正在为我的windows窗体应用程序进行设置方面的工作。在设置窗体上,我可以切换我的应用程序的提示音。默认的声音代码如下所示

public String defaultAlertTone = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sounds\\applause-2.wav"; 
至于设置,我已经包括了2个默认音调供用户通过组合框选择。组合框的代码如下所示

private void comboBoxSound_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBoxSound.SelectedIndex == 0)
        {
            ReportStatus("Alert tone changed to 'Beep(1)'!");
            backgroundFormObject.getSetting().defaultAlertTone = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sounds\\beep-1.wav";
        }
        else
        {

            ReportStatus("Alert tone changed to 'Beep(2)'!");
            backgroundFormObject.getSetting().defaultAlertTone = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sounds\\beep-2.wav";
        }

        string appPath = Path.GetDirectoryName(Application.ExecutablePath);

        Stream stream = File.Open(appPath + "\\setting.sd", FileMode.Create);
        BinaryFormatter bFormatter = new BinaryFormatter();


        bFormatter.Serialize(stream, backgroundFormObject.getSetting());
        stream.Close();
    }

为什么每当我选择另一种音调,播放声音时,效果仍然与最初的提示音相同,即掌声。我必须等待文件加载完成后才能播放吗?

使用以下代码自己解决了这个问题

private void comboBoxSound_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBoxSound.SelectedIndex == 0)
        {
            ReportStatus("Alert tone changed to 'Beep(1)'!");
            settingObject.defaultAlertTone = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sounds\\beep-1.wav";
        }
        else
        {

            ReportStatus("Alert tone changed to 'Beep(2)'!");
            settingObject.defaultAlertTone = Path.GetDirectoryName(Application.ExecutablePath) + "\\Sounds\\beep-2.wav";
        }

        string appPath = Path.GetDirectoryName(Application.ExecutablePath);

        Stream stream = File.Open(appPath + "\\setting.sd", FileMode.Create);
        BinaryFormatter bFormatter = new BinaryFormatter();


        bFormatter.Serialize(stream, settingObject);
        stream.Close();
    }