- Launch Visual Studio 2008 or 2010.
- Create a new project and give it a name
- Now if you want you can change your form properties such as form text, form icon etc.
- Now let's add the following controls to the form from the tool box on the left side. And change the text properties from their properties.
The name of the control | Control text |
button1 | Record |
Button2 | Stop and Save |
Button3 | Play |
label1 | Recording ... |
5. Now sort the tools added to the form like the picture below.
. Now we come to the part where we talk about the middle ground. Go to the code view of the form. The above codes are like:
1 2 3 4 5 6 7 8 | </div> <div> using System;</div> <div> using System.Collections.Generic;</div> <div> using System.ComponentModel;</div> <div> using System.Drawing;</div> <div> using System.Text;</div> <div> using System.Windows.Forms;</div> <div> |
Replace this code with the following code.
1 2 3 4 5 6 7 8 9 10 11 | </div> <div> using System;</div> <div> using System.Collections.Generic;</div> <div> using System.ComponentModel;</div> <div> using System.Data;</div> <div> using System.Drawing;</div> <div> using System.Linq;</div> <div> using System.Text;</div> <div> using System.Windows.Forms;</div> <div> using System.Runtime.InteropServices;</div> <div> |
. Now I will write the following code in the load event of the form. Double click on the form to go to the load event of the form. Then write the following code in load event. label1.Visible = false; Here label1 is hidden from the form.
. Now in the code view of the form
public Form1()
{
InitializeComponent();
}
This code is just below
[DllImport("winmm.dll")]
private static extern int mciSendString(string MciComando, string MciRetorno, int MciRetornoLeng, int CallBack);
string musica = "";
I write this code.
9. Now click the button1 button in the event
label1.Visible = true;
mciSendString("open new type waveaudio alias Som", null, 0, 0);
mciSendString("record Som", null, 0, 0);
I write this code.
10. Now click the button2 button in the event
label1.Visible = false;
mciSendString("pause Som", null, 0, 0);
SaveFileDialog save = new SaveFileDialog();
save.Filter = "wave|*.wav|MP3|*.mp3";
if (save.ShowDialog() == DialogResult.OK)
{
mciSendString("save Som " + save.FileName, null, 0, 0);
mciSendString("close Som", null, 0, 0);
}
I write this code.
11. Now click the button3 button in the event
if (musica == "")
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Wave|*.wav";
if (open.ShowDialog() == DialogResult.OK) { musica = open.FileName; }
}
mciSendString("play " + musica, null, 0, 0);
I write this code.
10. Now run the program by pressing F5 key and record the sound.
Download the source code .
Thanks everyone. If you like it, please let me know.
Post a Comment