Reputation: 439
I've been working on a fun little project wich is a SoundBoard & now I've stumbled on to a little issue, I get everything to work flawlessly, the only thing is that I really don't know how to add a Volume Control Bar since the volume in my software is really loud (it might be called a Volume Control Button). In any case, it's one of those where you can control the sound volume of the software, essentially its like a music player.
Does anyone know what I could try looking for?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.Stream = Properties.Resources.cow;
player.Play();
}
}
This is basically the code for every button.
Upvotes: 0
Views: 2126
Reputation: 439
I found this wich helped me a bit better, someone else might benefit from this aswell. Occurs when the Value property of a track bar changes, either by movement of the scroll box or by manipulation in code.
Upvotes: 0
Reputation: 4458
What you are looking for is a Slider control. You listen to the ValueChanged
event and change the volume appropriately.
private void slider1_ValueChanged (object sender, RoutedPropertyChangedEventArgs<double> e)
{
var slider = sender as Slider;
double value = slider.Value;
// assuming media is some sort of media control object
media.SetVolume (value);
}
You can set the maximum value of the slider, depending on your maximum volume. Or just do (value/slider.Maximum)
to get the slider position as a percent value, then you could do volume = (value/slider.Maximum) * max_volume
to set the volume as a percentage of the maximum.
EDIT: The SoundPlayer
class does not support setting the volume, but SoundEffectInstance
does. Please refer to the SoundEffectInstance MSDN article for more information.
Hope this is helpful.
Upvotes: 1