文章图片
demo 的实现图
下边是步骤和代码
1定义 时钟事件,定时的增加进度条的增量.
【c#devexpress GridContorl添加进度条】2:添加进度条
3;
定义字段属性
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Timers; using System.Windows.Forms; namespace ProgressBar { public partial class Form1 : Form { public Form1() { InitializeComponent(); jindu = new JinduModel(); jindu.jindu = 0; rarlist = new BindingList(); rarlist.Add(jindu); gridControl1.DataSource = rarlist; InitGridcontrol(); } JinduModel jindu; //BindingSource bs; BindingList rarlist; void InitGridcontrol() {// new System.Timers.Timer //实例化Timer类,设置间隔时间为10000毫秒; aTimer = new System.Timers.Timer(1000); //注册计时器的事件 aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); //设置时间间隔为2秒(2000毫秒),覆盖构造函数设置的间隔 aTimer.Interval = 2000; //设置是执行一次(false)还是一直执行(true),默认为true aTimer.AutoReset = true; //开始计时 aTimer.Enabled = true; } //指定Timer触发的事件 privatevoid OnTimedEvent(object source, ElapsedEventArgs e) { this.Invoke( new Action(()=> jindu.jindu++)); Console.WriteLine("触发的事件发生在: {0}", e.SignalTime); } //Timer不要声明成局部变量,否则会被GC回收 private static System.Timers.Timer aTimer; private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { if (e.Column.FieldName == "count") { int count = 10000; //Convert.ToInt32(System.Math.Ceiling(zipfileInfo.Length / 1024.0)); //datalist[0].count; //(int)this.gridView1.GetRowCellValue(e.RowHandle, "Count"); int index = (int)e.CellValue; e.DisplayText = string.Format("{0}/{1}", index, count); } }private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) { if (e.Column.FieldName == "count") { //int count = (int)this.gridView1.GetRowCellValue(e.RowHandle, "count"); //int index = (int)e.CellValue; repositoryItemProgressBar1.Maximum = 10000; //Convert.ToInt32(System.Math.Ceiling(zipfileInfo.Length / 1024.0)); //datalist[0].count; //count; e.RepositoryItem = repositoryItemProgressBar1; } } }}
class JinduModel : INotifyPropertyChanged { private int _jindu; public int jindu { get { return _jindu; } set { _jindu = value; OnPropertyChanged("jindu"); } } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); }}
转载于:https://www.cnblogs.com/zuochanzi/p/8962263.html
推荐阅读
- c#|原创C# Winform+DevExpress皮肤框架
- C# DevExpress之GridView同步滚动条记录方法
- DevExpress|DevExpress表格控件(GridView、GridControl)使用小结
- Unity|Unity UGUI ScrollView滑动到指定位置
- Unity|Unity Spine播放动画、动画播放结束回调、停止播放
- 视频教程|支付宝小程序3/3阶段_支付宝支付C#版-翟东平-专题视频课程
- NET|C# Try...Catch异常捕捉机制
- 所生成项目的处理器架构“MSIL”与引用“ ”的处理器架构“AMD64”不匹配。
- c#|windows 文件后缀名