C#ProgressBar意外的步骤

时间:2013-06-25 11:11:09

标签: c# .net progress-bar

我有一个ProgressBar和一个计时器。

我想显示1小时的进度:每秒增加1/3600。

当我运行应用程序时, 30分钟后,进度条的进度大约为100%。 我预计它会在30分钟后达到 50%。为什么会这样?

    public Form1()
    {
        InitializeComponent();
        this.timer1.Tick += new EventHandler(timer1_Tick);
        this.timer1.Interval = 1000;
        this.timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        this.progressBar1.PerformStep();
    }

-

        // 
        // progressBar1
        // 
        this.progressBar1.Location = new System.Drawing.Point(12, 29);
        this.progressBar1.MarqueeAnimationSpeed = 1000;
        this.progressBar1.Maximum = 3600;
        this.progressBar1.Name = "progressBar1";
        this.progressBar1.Size = new System.Drawing.Size(100, 23);
        this.progressBar1.Step = 1;
        this.progressBar1.TabIndex = 2;

1 个答案:

答案 0 :(得分:5)

您从工具箱中添加了计时器,并且已经设置了一个tick事件处理程序。这样它实际上被调用了两次。