0
votes

I'm trying to make a timer tick for 80 minutes while the progress bar keeps track of the current time, but the progress bar in C# Forms will not be accurate to the timer ticks. I have it set up for the timer to tick once every 1000 ms and in that tick it will add a step to the progress bar. The progress bar will not act as it should with the timer, does anyone know how to fix this?

public Form1()
{
    InitializeComponent();
    initTimers();
}

public void timer1_Tick(object sender, EventArgs e)
{
    progressBar1.Increment(1);
}

private void button1_Click(object sender, EventArgs e)
{
    if (button1.Text == "Go")
    {
        timer1.Start();
        button1.Text = "Stop";
    }
    else
    {
        timer1.Stop();
        button1.Text = "Go";
    }
}

public void initTimers()
{
    timer1.Tick += new EventHandler(timer1_Tick);
    timer1.Interval = 1000;
}

public void progressTimers()
{
    progressBar1.Value = 0;
    progressBar1.Minimum = 0;
    progressBar1.Maximum = 2;
    progressBar1.Step = 1;
    progressBar1.Visible = true;
}
1
Can you provide some code to help better diagnose the problem. - Adam
"to tick once every 1000 ms" Wouldn't it be simpler to say once a second? Also: 80 * 60 = 4800. Do you even have 4,800 pixels to play with? - Steve Wellens
Can you post inline in the question please, work fire walls don't let us see paste bin. - Adam
How doesn't the progress bar work with the timer? What is wrong? In your code, the progress bar's maximum is 2; what on earth for? Do you know what maximum is? As a matter-of-fact, you don't even call the function progressTimers(), but I am assuming that you wanted to call it in the function Form1(). - SuperPrograman
Basically the exact code you need. stackoverflow.com/questions/7259511/… - Adam

1 Answers

2
votes

You need to change this line:

progressBar1.Maximum = 2;

to:

progressBar1.Maximum = 80 * 60; // minutes * 60

And make sure you call progressTimers() :).