如何在winforms窗体中添加背景音乐??

hukai1221 2008-09-17 12:12:59
我先编写一个写日志的程序,希望可以在编写日志的时候程序播放出优雅的背景音乐?希望高手指点一下,谢谢!
...全文
335 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljb07976513524 2009-10-07
  • 打赏
  • 举报
回复
懦芞 2009-10-07
  • 打赏
  • 举报
回复
using System.Media;

private void Form1_Load(object sender, EventArgs e)
{
SoundPlayer msc = new SoundPlayer("文件路径");
msc.Play();
}
//文件路径为音乐文件在本地磁盘的路径,后缀名为.wav。
//例如C:\Program Files\Tencent\QQ\Misc\Sound\Classic\Audio.wav
king19840811 2008-09-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 liang4571231 的回复:]
using System.Media;
using System.IO;

SoundPlayer music = new SoundPlayer();

music = new SoundPlayer(Directory.GetCurrentDirectory() + "\\歌名.wav");
music.Play();
[/Quote]
此方法可行
king19840811 2008-09-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 JeffChung 的回复:]
用api, playSound?
[/Quote]
就是这个方法
liang4571231 2008-09-17
  • 打赏
  • 举报
回复
using System.Media;
using System.IO;

SoundPlayer music = new SoundPlayer();

music = new SoundPlayer(Directory.GetCurrentDirectory() + "\\歌名.wav");
music.Play();
JeffChung 2008-09-17
  • 打赏
  • 举报
回复
用api, playSound?
angelababa~ 2008-09-17
  • 打赏
  • 举报
回复
买个mp3,把耳机塞耳朵里,嘎嘎
mochencui 2008-09-17
  • 打赏
  • 举报
回复
就用SoundPlayer 把
LovingAlison 2008-09-17
  • 打赏
  • 举报
回复
using System.Media;
using System.IO;

SoundPlayer music = new SoundPlayer();

music = new SoundPlayer(Directory.GetCurrentDirectory() + "\\歌名.wav");
music.Play();
XPingguo 2008-09-17
  • 打赏
  • 举报
回复
SoundPlayer 简单
Bryan_JU 2008-09-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 liang4571231 的回复:]
using System.Media;
using System.IO;

SoundPlayer music = new SoundPlayer();

music = new SoundPlayer(Directory.GetCurrentDirectory() + "\\歌名.wav");
music.Play();
[/Quote]
就这个
maple0112 2008-09-17
  • 打赏
  • 举报
回复
public class Sound
{
public static void Play( string strFileName, PlaySoundFlags soundFlags)
{
PlaySound( strFileName, IntPtr.Zero, soundFlags);
// passes to Playsound the filename and a pointer
// to the Flag
}

[DllImport("winmm.dll")] //inports the winmm.dll used for sound
private static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags );
}

[Flags] //enumeration treated as a bit field or set of flags
public enum PlaySoundFlags: int
{

SND_SYNC = 0x0000, /* play synchronously (default) */
SND_ASYNC = 0x0001, /* play asynchronously */
SND_NODEFAULT = 0x0002, /* silence (!default) if sound notfound */
SND_LOOP = 0x0008, /* loop the sound until nextsndPlaySound */
SND_NOSTOP = 0x0010, /* don't stop any currently playingsound */
SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
SND_FILENAME = 0x00020000, /* name is file name */
SND_RESOURCE = 0x00040004 /* name is resource name or atom */
}

110,586

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧