异步调用进度条窗体弹出加载数据
2021-03-18 02:26
                         标签:com   数据   _for   调用   icon   cti   turn   bool   sum    异步调用进度条窗体弹出   public partial class LoadProgressBar : Form         public void SetProgressMaxValue(int value, string name)         public void SetValue(int value, int totalValue)         private void LoadProgressBar_FormClosing(object sender, FormClosingEventArgs e)             }         private void closed_Pic_Click(object sender, EventArgs e)         private void timer1_Tick(object sender, EventArgs e)     } 异步调用进度条窗体弹出加载数据 标签:com   数据   _for   调用   icon   cti   turn   bool   sum    原文地址:https://www.cnblogs.com/wangyonglai/p/12372023.html
    {
        int losttime = 0;
        /// 
        /// 是否可以关闭窗体
        /// 
        public bool ClosedFlag = false;
        public LoadProgressBar()
        {
            InitializeComponent();
        }
        {
            progressBar1.Maximum = value;
            progressBar1.Value = 0;
            nameLab.Text = name;
            losttime = 0;
            Console.WriteLine("Maximum:" + value);
        }
        {
            try
            {
                losttime = 0;
                this.progressBar1.BeginInvoke(new Action(() =>
                {
                    progressBar1.Maximum = totalValue;
                    int tempvalue = progressBar1.Value + value;
                    if (tempvalue                     {
                        speedLab.Text = tempvalue.ToString("D2") + "/" + totalValue.ToString("D2");
                        progressBar1.Value = tempvalue;
                    }
                    Console.WriteLine("tempvalue:" + tempvalue);
                }));
            }
            catch
            { }
        }
        {
            if (ClosedFlag == false)
            {
                if (losttime > 30)
                {
                    this.DialogResult = DialogResult.Cancel;
                    return;
                }
                if (MessageBox.Show("正在导出文件,是否要中断?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.DialogResult = DialogResult.Cancel;
                }
                else
                {
                    e.Cancel = true;
                    //this.DialogResult = DialogResult.Cancel;
                }
            else
            {
                this.DialogResult = DialogResult.OK;
            }
        }
        {
            this.Close();
        }
        {
            losttime++;
            if (losttime > 30)
            {
                this.Close();
            }
        }