How To Make A Sound Recorder In C#

sound recorder

hey ,today i will let you know how to create a sound recorder in c# by the way this is just a simple tutorial but this will let you know about the recording so you can make a  advanced recording application ok now first create a new project and name it and you need three buttons and one label so drag and and drop them from tool box into your form and now change the text of the each button as below

Button 1 - Record
Button2 - Stop And Save
Button3 - Play

now just keep the label 1 text empty now just double click your form and erase everything and add the whole code there

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

//Author : Mohamed Shimran
//Blog : http://www.ultimateprogrammingtutorials.blogspot.com

namespace soundrecorder
{
    public partial class Form1 : Form
    {
        [DllImport("winmm.dll")]
        private static extern int mciSendString(string MciComando, string MciRetorno, int MciRetornoLeng, int CallBack);

        string musica = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Visible = true;
            mciSendString("open new type waveaudio alias Som", null, 0, 0);
            mciSendString("record Som", null, 0, 0);
        
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label1.Visible = false;
            mciSendString("pause Som", null, 0, 0);

          

            SaveFileDialog save = new SaveFileDialog();

            save.Filter = "wave|*.wav";


            if (save.ShowDialog() == DialogResult.OK)
            {

                mciSendString("save Som " + save.FileName, null, 0, 0);
                mciSendString("close Som", null, 0, 0);
            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (musica == "")
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Wave|*.wav";
                if (open.ShowDialog() == DialogResult.OK) { musica = open.FileName; }
            }
            mciSendString("play " + musica, null, 0, 0);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Visible = false;
        }


    }
}


now debug and enjoy .