I am new to C#, and am making a metronome. I am using SoundPlayer to play some wav files I have in a folder when the user clicks a play button. However, for the pause button the new SoundPlayer I have created is not available to stop/pause. How can/can I make this global? Here is my code:
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;
using System.Media;
namespace Metronome
{
    public partial class Form1 : Form
    {
        int mov;
        int movX;
        int movY;
        decimal speed;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void label1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            mov = 1;
            movX = e.X;
            movY = e.Y;
        }
        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if(mov==1)
            {
                this.SetDesktopLocation(MousePosition.X - movX, MousePosition.Y - movY);
            }
        }
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            mov = 0;
        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            speed = BPMTime.Value;
            speed = Decimal.ToInt16(speed);
            string num = speed.ToString();
            SoundPlayer sp = new SoundPlayer(@"C:\Users\user\Desktop\Metronome\Metronome\Sounds\" + num + " BPM.wav");
            sp.PlayLooping();
        }
        private void pictureBox2_Click(object sender, EventArgs e)
        {
        }
    }
}
pictureBox2 is my pause button. However. when I try to control the SoundPlayer from it, it can't find an instance of it, because (I'm assuming) it was defined inside my Play Button/Picture Box 1 click event. Is there any way I can change this? Any help would be greatly appreciated.