将音频资源连接到trackBar Visual Studio C#.NET [英] Connect Audio resources to a trackBar Visual Studio C# .NET

查看:68
本文介绍了将音频资源连接到trackBar Visual Studio C#.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好CodeProject的用户!



基本上我已经完成了我的第一个项目之一&我想添加一些功能,问题是我真的不知道如何将这个KeyFeature添加到我的应用程序中,我想我知道需要做什么但不确定,只是想知道我的方式是什么在谈到这个问题时,思考会有任何意义。



所以这里是..



我最近创建了一个SoundBoard,它使用我添加到Visual Studio(音频文件)和它们连接到按钮,所以当我按下按钮时它会播放声音,(下面提供代码)它不是WMP(Windows Media Player)驱动的&我的意思是我没有使用内置的Windows Media Player功能,因为这使事情变得非常复杂。

所以这就是我想做的事情,但我不想这样做,如果那里这是一种更简单的方法。



我想添加一个trackBar,它允许我调整整个应用程序的音量。我认为我需要做的是实现一个代码,当用户更改trackBar时,该代码会更改该特定应用程序的Windows系统卷。



这就是漂亮的很多我是如何考虑创建此功能,它听起来像克雷?我想在这里过于先进吗?你会用什么方式制作这样的东西?



(如果这是一个不恰当的问题我会删除它!)



问候!





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!


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;
        }
    }
 }

推荐答案

添加轨迹栏非常简单,请参阅 TrackBar类 [ ^ ]

这个控件看起来很无聊,所以你可能想看看这个高级TrackBar(滑块)控制(C#和VB.NET) [ ^ ]



另外请注意,您应该使用按钮考虑您的设计。它有点静态,如果你有那种老师,他会说我想要10个按钮随机播放声音,你需要在按钮文本字段中显示声音的名称。

您可以查看如何使用词典以及如何动态创建按钮。
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.


这篇关于将音频资源连接到trackBar Visual Studio C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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