-1

I currently have a button object that starts a wav file playing, as well as a progress bar and a timer, all of which are toolbox objects in Visual Studio 2010. The problem is that, when I open the form, the progress bar automatically starts filling up. How can I get it to start only when I click on the button?

Here is the code I have so far:

 private void playsong1_Click(object sender, EventArgs e)
    {
        SoundPlayer sndplayer = new SoundPlayer(Programming_assignment.Properties.Resources.Back_In_Black);
        sndplayer.Play();

        timer1.Enabled = true;

    }

    private void progressBar1_Click(object sender, EventArgs e)
    {

    }
    private void timer1_Tick(object sender, EventArgs e)
    {            
        if (progressBar1.Value < 256)
        {
            progressBar1.Value++;
        }
    }
Tom Leverett
  • 1
  • 1
  • 1
  • 1
    Perhaps u can check here "How do I implement a progress bar in C#? http://stackoverflow.com/questions/1259949/how-do-i-implement-a-progress-bar-in-c " – NoWar Dec 13 '12 at 18:08

1 Answers1

0

Looks like you have timer1.Enabled = true or timer1.Start() in form's constructor or Load event handler. BTW check timer's Enabled property in designer - maybe you set it to true by default.

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
  • I had a look in the designer and the timer enabled property was set to false. I've put in the same thing for the progress bar as well, i.e. 'progressBar1.Enabled = true', would this help? Also would having an if statement inside the button click void be of any use? – Tom Leverett Dec 13 '12 at 18:36
  • No, disabling progress bar will not solve your issue. Just go and find all usages of `timer1` variable and check where you enable timer or start it. – Sergey Berezovskiy Dec 13 '12 at 18:48
  • 1
    Just gone through it all and found it, i'd set it to true right at the start! Thanks a lot man, you really helped a noobie programer out! – Tom Leverett Dec 13 '12 at 20:33