Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello fellow users of CodeProject!

So basically I have completed one of my first projects & I would like to add some features, the thing is that I dont really know how to add this one "KeyFeature" to my app, I think I know what needs to be done but not sure, would just like to know if my way of thinking makes any sence when it comes to this.

So here it is..

I recently created a SoundBoard that uses resources I added to Visual Studio (Audio Files) & they are connected to buttons so when I press a button it plays a Sound,(Providing the code down below) it is not WMP(Windows Media Player) driven & by that I mean that I did not use the built in Windows Media Player Feature because that made things very complicated.
so this is what I would like to do, but I wouldnt want to do it if there is a easier way of doing it.

I would like to add a trackBar that allows me to adjust the volume of the whole app & what I think I would need to do is implement a code that changes the windows system volume for that specific application when the user is making changes to the trackBar.

Thats pretty much how I was thinking of going by with creating this feature, does it sound cray? Am I trying to be too advanced here? What way would you go by of making something like this?

(If this is a inappropriate question I will delete it!)

Regards!


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
/// <summary>
/// Version: 1.0
/// SoundBoard
/// Created By Varga
/// Date 2015-10-29
/// Category: Fun
/// </summary>
namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //Adding All The Keys That Needs To Be Binded Check Line 127
            this.KeyPreview = true;
            this.KeyDown += new KeyEventHandler(button1_KeyDown);
            this.KeyDown += new KeyEventHandler(button2_KeyDown);
            this.KeyDown += new KeyEventHandler(button3_KeyDown);
            this.KeyDown += new KeyEventHandler(button4_KeyDown);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.cow;
            player.Play();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.owl;
            player.Play();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.ram;
            player.Play();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.water;
            player.Play();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.wind;
            player.Play();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.fire;
            player.Play();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.car;
            player.Play();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.horn;
            player.Play();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.happy;
            player.Play();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.farm;
            player.Play();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.pig;
            player.Play();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.horse;
            player.Play();
        }


        //Adding All The Keys That Is Being Binded
        private void button1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "F1")

            {
                button1_Click(null, null);
            }
        }

        private void button2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "F2")

            {
                button2_Click(null, null);
            }
        }
        //The Next Page Button.
        private void button14_Click(object sender, EventArgs e)
        {
            panel1.Visible = true;
        }

        private void beep_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.beep;
            player.Play();
        }

        private void plate_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.office;
            player.Play();
        }

        private void Fatality_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.bird;
            player.Play();
        }

        private void FHRITP_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.shark;
            player.Play();
        }

        private void Finish_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.race;
            player.Play();
       }

        private void F***_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.themesong;
            player.Play();
        }

        private void Headshot_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.bitgame;
            player.Play();
        }

        private void Nathan_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.harry;
            player.Play();
        }

        private void Nuke_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.nick;
            player.Play();
        }

        private void Sadhorn_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.cash;
            player.Play();
        }

        private void Shots_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.eagle;
            player.Play();
        }

        private void Sonata_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.elephant;
            player.Play();
        }

        private void Surprise_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.tiger;
            player.Play();
        }

        private void Weed_Click(object sender, EventArgs e)
        {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.Stream = Properties.Resources.duck;
            player.Play();
        }

        private void button3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "F3")

            {
                button3_Click(null, null);
            }
        }

        private void button4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "F4")

            {
                button3_Click(null, null);
            }
        }
        //Previous button
        private void Previous_Click(object sender, EventArgs e)
        {
            panel1.Visible = false;
        }
    }
 }
Posted
Updated 17-Nov-15 22:10pm
v3
Comments
George Jonsson 18-Nov-15 4:02am    
The c-u-n-t button seems a bit rude ;-)
BladeLogan 18-Nov-15 4:07am    
Oh, yeah so I have a friend who works on the project with me, please excuse me for some of the faul language that might occur in the code. :(

1 solution

Adding a track bar is pretty simple, see TrackBar Class[^]
This control looks pretty boring, so you might want to have a look at this one Advanced TrackBar (Slider) Control with MAC Style (C# & VB.NET)[^]

On another note, you should consider your design with the buttons. It is kind of static and if you have the kind of teacher I had, he will come and say "I want 10 buttons with random sound playing and you need to show the name of the sound in the buttons text field."
You can look into how to use a Dictionary and how to create buttons dynamically.
 
Share this answer
 
Comments
BladeLogan 18-Nov-15 4:33am    
Thanks for the great tips! & I can agree that it is pretty boring but its just a fun little project that I am currently working on as a side project, & I took a look at the link that you sent me, I really couldnt find anything about Volume control, did I miss it?
George Jonsson 18-Nov-15 4:46am    
You didn't miss it.
A slide control give you a value between min and max, e.g. 0 - 255, and in the event ValueChanged (or similar) you get the new value.
The volume is just a number you send into the volume control.
BladeLogan 18-Nov-15 5:07am    
Thank you for explaining sir!
George Jonsson 18-Nov-15 5:08am    
You are welcome
BladeLogan 18-Nov-15 8:22am    
Hey this might be a silly question, but where do I find information about the valueChanged event & how to use it, been looking for about an hour now & I still cant get it to work sorry kinda new, 2 months in.

This is my current code for the trackBar & I know there is something missing.

private void trackBar1_Scroll(object sender, EventArgs e)
{
trackBar1.Minimum = 0;
trackBar1.Maximum = 100;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900