控制trackBar1_Scroll事件以更改音量。 [英] Controlling the trackBar1_Scroll event to change the volume.

查看:119
本文介绍了控制trackBar1_Scroll事件以更改音量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,所以我越来越接近未解决问题的神秘面纱(双关语)



所以,过去3天我一直试图解决这个问题问题&它终于找到了我,这让我很沮丧生气的我想把电脑扔出窗外(另一个不好的双关语)



发生的事情是我试图用trackBar来控制我的音板的音量。



它不是由Windows Media Player驱动它只是一些资源(音频文件)这是一个非常无聊的项目它真的没什么特别但我真的似乎不能让代码工作。



(如有必要,将提供.cs文件)我想要完成的是我想创建一个连接到winForm app&让用户控制WinForm本身的音量。



这是trackBar的代码,或者这是我到目前为止所获得的代码。我知道它并不多,但我对trackBars非常不好。



这是按钮和代码的代码。按下时播放的声音。



Hello, So I am getting closer to the mystery of the unsolved issue (Pun)

So, for the past 3 days I have been trying to solve this issue & it is finally getting to me, it is making me frustrated & angry & I would like to throw the computer out of the window (Another bad pun)

What is going on is that I am trying to control my soundboard's volume with a trackBar.

it is not driven by Windows Media Player it is simply just some resources (Audio Files) It is a really boring project its really nothing special but I really cant seem to get the code to work.

(Will provide the .cs files if necessary) What I am trying to accomplish is that I want to make a trackBar that connects to the winForm app & lets the user control the volume of the WinForm itself.

Here is the code for the trackBar, or this is what I've gotten so far. I know its not much but I am really bad with trackBars.

Here is the code for the button & the sound being played when pressing it.

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.Stream = Properties.Resources.cow;
player.Play();





&这是trackBar的代码。我真的似乎无法连接这两个。

任何提示?



& this is the code for the trackBar. I really cant seem to connect the two.
Any tips?

private void trackBar1_Scroll(object sender, EventArgs e)
{
    MySoundPlayer.Volume = trackBar1.Value;
}

推荐答案

你好再次



制作这个变量您的Form类的成员

Hello again

Make this variable a member of your Form class
private System.Media.SoundPlayer player;





然后在表格的构造函数中



Then in the constructor of the Form

public MyForm()
{
    player = new System.Media.SoundPlayer();
}





然后在你的按钮点击代码



Then in your button click code

private void MyAwsomeButton_click(object sender, EventArgs e)
{
    player.Stream = Properties.Resources.cow;
    player.Play();
}







private void trackBar1_Scroll(object sender, EventArgs e)
{
MySoundPlayer.Volume = trackBar1.Value;
    player.Volume = trackBar1.Value;
}



现在这两个已连接。



你能发现差异吗?



[更新]

因此SoundPlayer没有音量属性。

我有点想你已经检查过了,但是这里有一些适合你的阅读。



适用于您的应用程序的同步卷控制 [ ^ ]



在C#中控制音量 [ ^ ]



祝你好运。


Now the two are connected.

Can you spot the difference?

[UPDATE]
So the SoundPlayer doesn't have a volume property.
Well I kind of thought you had checked that, but OK here is some reading for you.

A Synchronized Volume Control for your Application[^]

Controlling Sound Volume In C#[^]

Good luck with your quest.


这篇关于控制trackBar1_Scroll事件以更改音量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆