从Windows选择声音并播放 [英] Selecting sounds from Windows and playing them
本文介绍了从Windows选择声音并播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个WinForms应用程序.该应用程序具有首选项"部分,用户可以在其中选择显示警报时播放的声音.
I have a WinForms app. This app has a Preferences section where the user will be able to select which sounds are played when an alert is being displayed.
是否可以有一个组合框,用户可以在其中从Windows存储的声音中选择声音,例如紧急停止",紧急蜂鸣"等.这些可以在控制面板" >>声音和警报"部分中找到.
Is it possible to have a combobox where the user can select from the Windows stored sounds such as "critical stop", "critical beep" and so on. These are found in the "Control Panel" >> "Sounds and Alerts" section.
是否还可以有一个播放按钮来测试声音?
Is it also possible to have a play button to test the sounds out?
推荐答案
尝试一下:
private void Form1_Load(object sender, EventArgs e)
{
var systemSounds = new[]
{
System.Media.SystemSounds.Asterisk,
System.Media.SystemSounds.Beep,
System.Media.SystemSounds.Exclamation,
System.Media.SystemSounds.Hand,
System.Media.SystemSounds.Question
};
comboBox1.DataSource = systemSounds;
comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
((System.Media.SystemSound)comboBox1.SelectedItem).Play();
}
这篇关于从Windows选择声音并播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文