Winform中进度条(ProgressBar)的使用
2022-04-13 08:19 NO.27 阅读(1136) 评论(0) 编辑 收藏 举报一、实现
/// <summary> /// 初始化进度条 /// </summary> /// <param name="progressBar">进度条组件</param> /// <param name="minValue">当前进度值</param> /// <param name="maxValue">进度显示标签</param> private void InitProgressBar(ProgressBar progressBar,int minValue,int maxValue) { if (progressBar == null || minValue < 0 || maxValue < 0 || minValue >= maxValue) return; progressBar.Minimum = minValue; progressBar.Maximum = maxValue; } /// <summary> /// 启动进度条 /// </summary> /// <param name="progressBar">进度条组件</param> /// <param name="value">当前进度值</param> /// <param name="lable">进度显示标签</param> private void StartProgressBar(ProgressBar progressBar, int value, Label lable) { if (progressBar == null || lable == null) return; Application.DoEvents(); progressBar.Value = value; int tmp = value * 100 / progressBar.Maximum; lable.Text = tmp + "%__"+value+"/"+progressBar.Maximum; lable.Refresh(); progressBar.Refresh(); }
二、使用
int index = 1; int maxIndex = dt.Rows.Count; InitProgressBar(progressBar1,index,maxIndex); foreach (DataRow dr in dt.Rows) { StartProgressBar(progressBar1,index,label4); index++; //具体逻辑 } }