路径不是合法形式的错误c#

本文关键字:错误 路径 | 更新日期: 2023-09-27 18:26:16

我正试图通过Form1_Load上的AudioHandler()设置MenuTrack路径,但它没有将路径添加到Menutrack。mts mts mts-mts-

namespace NGTurnBased
{
class MyVariables
{
    public static string Menu_Track;
    public static SoundPlayer AudioPlayer = new SoundPlayer(Menu_Track);
    public static int Essence = 0;

}
}

 private void Form1_Load(object sender, EventArgs e)
    {
        rdb_Ryu.Click += Character_Selected;
        rdb_momiji.Click += Character_Selected;
        getForm();
        AudioHandler();

    }
   private void AudioHandler()
    {
        if (currentForm != "test")
        {
            MyVariables.Menu_Track = @"C:'Users'Gary'Desktop'NGRPG'Volf_BGM.wav";
        }
        MyVariables.AudioPlayer.Play();
    }

路径不是合法形式的错误c#

public static string Menu_Track;
public static SoundPlayer MenuSelection = new SoundPlayer(Menu_Track);

您应该在此处指定SoundPlayer的路径。目前,您有新的SoundPlayer(null)->,这不是wav文件的有效路径。

编辑:感谢评论@ThomasLevsque