Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to include a functionality in my application such that when the user clicks on a button, the user should be able to record the voice, and when stopped, the sound should be saved. Here's what I wrote for the Start and Stop button

int i=0;
private void button1_Click(object sender, EventArgs e)
      Button btnStrtStop = (Button)sender;
      if (i == 0)
        //Record code
        btnStrtStop.BackgroundImage = System.Drawing.Image.FromFile("RecordPressed.png");
        toolTip1.SetToolTip(button1, "Stop");
        mciSendString("Open new type waveaudio alias RecSound", "", 0, 0);
        mciSendString("Record Recsound", "", 0, 0);
        //Button3.BackgroundImage = System.Drawing.Image.FromFile(ofdButtonPicture.FileName)
        i = 1;
        //Stop Code
string strAppDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
        btnStrtStop.BackgroundImage = System.Drawing.Image.FromFile("RecordHot.png");
        toolTip1.SetToolTip(button1, "Record");
        mciSendString("Save RecSound" + strAppDir + "record.wav", "", 0, 0);
        mciSendString("Close RecSound", "", 0, 0);
        i = 0;

The problem I am facing is that the background image is not find the backgournd image for Start Stop button. I am not using the Open File Dialog but I have the two png files in the project directory itself.

For the play button, I have used

System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
myPlayer.SoundLocation = @"c:\file.wav";

I would have to load the file from the same path in the debug folder. how to specify that?
Also, unlike the previous code in the filename is constant "file.wav ", I want to provide a custom filename for each file we save.

1 solution

The images as you say are being kept in the project directory.

When you run or compile the application it will end up in another location e.g. bin\debug or some other location.

The app will have no concept of where the images exist. You will need to specify the files are 'copied to output' in the IDE, or include the images as some form of embedded resource within the project exe.

Another option is to add 2 image controls, point the image source to the files, and then show/hide these to images as required. That will ensure the images are included within the application.
Share this answer
optimus_prime1 9-Oct-10 8:23am    
Thanks for the reply.
The images problem is solved but the main issue now is that on pressing the "Start Recording button", nothing happens and similar is the case with Stop Recording. Play button also doesn't do anything :o/

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