进度条或计时器组合

时间:2012-07-10 22:28:25

标签: c# forms timer progress-bar

我正在尝试将计时器打勾80分钟,同时进度条会跟踪当前时间,但C#表单中的进度条对于计时器刻度不准确。我已将它设置为定时器每1000毫秒勾选一次,在该刻度中它将向进度条添加一个步骤。进度条不会像计时器那样动作,有人知道如何解决这个问题吗?

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 个答案:

答案 0 :(得分:2)

您需要更改此行:

progressBar1.Maximum = 2;

为:

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

请务必致电progressTimers():)。