DevExpress_常用控件13_ProgressBarControl

3、Common Controls

3.10 ProgressBarControl控件

进度条

效果如下:


示例代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;
using System.Threading;

namespace DXApplication_1
{
    public partial class ProgressBarControlForm : DevExpress.XtraEditors.XtraForm
    {
        public ProgressBarControlForm()
        {
            InitializeComponent();
        }
        private void Encapsulation_DeleteFiles()
        {
            string dirPath = "C:\\Users\\teeking_scx\\source\\repos\\DXApplication_1\\test";
            if (Directory.Exists(dirPath))
            {
                string[] fileArr = Directory.GetFiles(dirPath);
                progressBarControl1.Properties.Step = 1;
                progressBarControl1.Properties.PercentView = true;
                progressBarControl1.Properties.Maximum = fileArr.Length;
                progressBarControl1.Properties.Minimum = 0;
                Thread.Sleep(10000);
                foreach (string fileName in fileArr) {
                    File.Delete(fileName);
                    progressBarControl1.PerformStep();
                    progressBarControl1.Update();
                    Thread.Sleep(1000);
                }
            }
        }
        private void ProgressBarControl_Load(object sender, EventArgs e)
        {
            //方法一:使用Thread类
            ThreadStart threadStart = new ThreadStart(Encapsulation_DeleteFiles);//通过ThreadStart委托告诉子线程执行什么方法  
            Thread thread = new Thread(threadStart);
            thread.Start();//启动新线程
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/springsnow/p/10298705.html
今日推荐