概述
基于.NET Framework 4.0开发,包含滑块设置音量,键盘F1、F2调节音量。
通过滑块调节系统音量核心代码
/// <summary>
/// 滑块设置音量
/// </summary>
private void SetVolume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (isVolumeChange)
{
return;
}
this.Dispatcher.BeginInvoke(new Action(() =>
{
VolumeHelper.VolumeHelper.SetVolume((int)SetVolume.Value);
TextVolume.Text = Volume + ((int)SetVolume.Value).ToString();
SoundPlayer player = new SoundPlayer();
player.Stream = Properties.Resources.Volume;
player.Play();
}));
}
通过键盘系统音量核心代码
#region 获取键盘键值
private void Window_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
switch (e.Key.ToString())
{
case "F1":
VolumeUP();
this.Dispatcher.BeginInvoke(new Action(() =>
{
SetVolume.Value = SetVolume.Value + 5;
SoundPlayer player = new SoundPlayer();
player.Stream = Properties.Resources.Volume;
player.Play();
}));
break;
case "F2":
VolumeDown();
this.Dispatcher.BeginInvoke(new Action(() =>
{
SetVolume.Value = SetVolume.Value - 5;
SoundPlayer player = new SoundPlayer();
player.Stream = Properties.Resources.Volume;
player.Play();
}));
break;
}
}
#endregion
/// <summary>
/// 加大音量
/// </summary>
private void VolumeUP()
{
this.Dispatcher.Invoke(new Action(delegate
{
WindowInteropHelper wndHelper = new WindowInteropHelper(this);
for (int i = 0; i < 5; i++)
{
SendMessage(wndHelper.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
SoundPlayer player = new SoundPlayer();
player.Stream = Properties.Resources.Volume;
player.Play();
}
}));
}
/// <summary>
/// 降低音量
/// </summary>
private void VolumeDown()
{
this.Dispatcher.Invoke(new Action(delegate
{
WindowInteropHelper wndHelper = new WindowInteropHelper(this);
for (int i = 0; i < 5; i++)
{
SendMessage(wndHelper.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
SoundPlayer player = new SoundPlayer();
player.Stream = Properties.Resources.Volume;
player.Play();
}
}));
}
C# 音量调节Demo源码下载
最后
以上就是平常黑米为你收集整理的C# Windows系统音量调节Demo源码的全部内容,希望文章能够帮你解决C# Windows系统音量调节Demo源码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复