Beispiel #1
0
        private delegate void DoDataDelegate(object StepValue);//创建委托

        /// <summary>
        /// 进度循环
        /// </summary>
        /// <param name="StepValue"></param>
        private void DoData(object StepValue)
        {
            try
            {
                if (ExcelProgBar.InvokeRequired)
                {
                    DoDataDelegate doDelgt = DoData;
                    ExcelProgBar.Invoke(doDelgt, StepValue);
                }
                else
                {
                    //循环执行当前进度
                    ExcelProgBar.Maximum = (int)StepValue;
                    for (int i = 0; i < (int)StepValue; i++)
                    {
                        ExcelProgBar.Value = i;
                        int PercMsg = i * 100 / (int)StepValue;
                        lblPercent.Text = PercMsg.ToString() + "%";
                        Thread.Sleep(100);
                        Application.DoEvents();
                    }
                    //ProgressThread.Abort();//关闭线程
                    //Environment.Exit(0);
                    this.Close();
                }
            }catch (Exception ex)
            {
                MessageBoxEx.Show(ex.Message, "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
        }
        /// <summary>
        /// 进行循环
        /// </summary>
        /// <param name="StepValue">进度值</param>
        private void DoData(object StepValue)
        {
            try
            {
                if (ExcelProgBar.InvokeRequired)
                {
                    DoDataDelegate DDelgt = DoData;
                    ExcelProgBar.Invoke(DDelgt, StepValue);
                }
                else
                {
                    ExcelProgBar.Maximum = (int)StepValue;//获取当前最大值

                    for (int i = 0; i < (int)StepValue; i++)
                    {
                        lblPercent.Text    = ProgressValue; //获取进度百分比
                        ExcelProgBar.Value = CurrentValue;  //获取当前进度
                        Application.DoEvents();
                    }
                    MessageBoxEx.Show("导出成功!");
                }
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show(ex.Message);
            }
        }