日期:2014-05-18  浏览次数:20773 次

如何实现声音随弹出窗口的弹出而播放,随弹出窗口的关闭而停止?
我在windows应用程序中添加了一个类,写了如下代码,在From1的按钮单击事件下调用Sound.Play("exa");来实现的播放声音,现我想实现如题所要的效果,该怎么实现呢?
using System.Collections;
using System.ComponentModel;
using System.Runtime.InteropServices;


namespace Play
{
internal class Helpers
{
[Flags]
public enum PlaySoundFlags : int
{
放  
SND_ASYNC = 0x0001, /* play asynchronously */ //异步播放  

}

[DllImport("winmm")]
public static extern bool PlaySound(string szSound, IntPtr hMod, PlaySoundFlags flags);
}

public class Sound
{
//播放
public static void Play(string strFileName)
{
   strFileName = @"..\..\music\background.WAV";

}

//调用PlaySound方法,播放音乐  
Helpers.PlaySound(strFileName, IntPtr.Zero, Helpers.PlaySoundFlags.SND_ASYNC);
}

//关闭
public static void Stop()
{
Helpers.PlaySound(null, IntPtr.Zero, Helpers.PlaySoundFlags.SND_ASYNC);
}
}
}

------解决方案--------------------
new 一个 Form 的时候调用播放的方法?
然后在这个新 Form 的 Close() 的时候调用关闭的方法?
------解决方案--------------------
new 一个 Form 的时候调用播放的方法? 
然后在这个新 Form 的 Close() 的时候调用关闭的方法?


这样就可以了
------解决方案--------------------
探讨
new 一个 Form 的时候调用播放的方法?
然后在这个新 Form 的 Close() 的时候调用关闭的方法?
这样就可以了