作了一个应用程序,想在程序启动播放时候有一小段.wav声音 
新建一个Class1类中
[DllImport("winmm.dll", EntryPoint="PlaySound")]
     public static extern bool PlaySound_DllImport(string pszSound,IntPtr hmod ,int fdwSound )我把xx.wav的声音文件,放在项目目录下的sound文件夹中,
问如何在Form1_Load的时候播放这一小段声音?

解决方案 »

  1.   

    private string soundFileName=文件地址;
    应该是Class1.PlaySound_DllImport(this.soundFileName,resourceHandle,0);
    文件地址这里该这么写??
      

  2.   

    我怎么记得api不是这么申明的
      

  3.   

    private static void Play(string file)
            {
                int flags = SND_ASYNC | SND_NODEFAULT;
                sndPlaySound(file, flags);
            }        [DllImport("winmm.dll")]
            private extern static int sndPlaySound(string file, int uFlags);
      

  4.   

    filepath = Server.MapPath("sound/a.wav")
      

  5.   

    winform中就直接取相对路径好了
      

  6.   

    老大们...说一下撒! 
    @sound\xx.wav不行啊..
      

  7.   

    winform中没有相对路径的概念,只能得到应用程序的路径
    string dir = Application.StartupPath;
    然后再用SubString处理。
      

  8.   

    放个声音而已,没那么复杂吧!System.Media.SoundPlayer sdPlayer;
    sdPlayer = new System.Media.SoundPlayer(Sound文件名);
    sdPlayer.Play();