使用timer控件控制进度条

时间:2023-03-08 18:57:14
使用timer控件控制进度条

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ECS.Simulate
{
    public partial class FrmProgress : Form
    {
        public FrmProgress()
        {
            InitializeComponent();
            this.CenterToParent();
            progressBar1.Maximum = 1000;
            progressBar1.Step = 10;
            timer1.Enabled = true;
        }

private void FrmProgress_Load(object sender, EventArgs e)
        {

}

private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.progressBar1.Value == this.progressBar1.Maximum)
            {
                this.progressBar1.Value = this.progressBar1.Minimum;
            }
            else
            {
                if (StatusData.flag)
                {
                    this.progressBar1.PerformStep();
                    this.Close();
                    this.Dispose();
                    GC.Collect();
                    StatusData.flag = false;
                }
                this.progressBar1.PerformStep();
            }
        }
    }

public class StatusData
    {
        public static bool flag = false;
    }

}