C#,winForm中怎样添加声音文件?

lgp1988 2008-09-26 11:32:41
假如我要让鼠标经过某一按钮上时,要发出一个声音,请问这个怎样做??
...全文
586 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
北京的雾霾天 2008-09-26
  • 打赏
  • 举报
回复
private void button1_MouseEnter(object sender, EventArgs e)
{
SystemSounds.Asterisk.Play();
}
wanghui0380 2008-09-26
  • 打赏
  • 举报
回复
在你要触发的事件里写
System.Media.SoundPlayer player = new SoundPlayer();
player.SoundLocation = "c:\\test.wav";
player.LoadAsync();
player.PlayLooping(); //asynchronous (loop)playing in new thread
Thread.Sleep(5000);
player.Stop();

  • 打赏
  • 举报
回复
在这个按钮事件的MouseMove里面写播放声音的代码
播放声音,可以使用c#自带的media。
using System.Media;
然后
SoundPlayer soundPlayer = new SoundPlayer();
soundPlayer.SoundLocation = Application.StartupPath + "\\" +"Sound"+"\\"+"xinxi.wav"; //声音的地址一般放在bin/debug中
soundPlayer.Load();
soundPlayer.Play();

问题得到解决
Red_angelX 2008-09-26
  • 打赏
  • 举报
回复
MouseOver还是DragOver里添加事件

110,566

社区成员

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

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

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