Devexpress控件中,進度條控件為ProgressBarControl, 在數據型控件中進度條為RepositoryItemProgressBar.
常用的設置
- 樣式或者皮膚
- 進度設置
- 進度文字顯示
樣式或者皮膚
進度控件的默認顏色是無法直接更改的,因為顯示的優先是樣式和皮膚,只有設置不使用默認主題就可以進行改變了.
progressbar.LookAndFeel.UseDefaultLookAndFeel = false;
進度設置
進度的三要素:最大值 當前值 遞增量
progressbar.Maximum = 200; //總進度 progressbar.Step=1; //進度的遞增量 progressbar.Text="55"; //當前進度
進度文字顯示
進度條在展示進度的同時,還可以顯示百分比(可格式化精度)或詳細進度,亦可自定義顯示
progressbar.ShowTitle = true; //允許顯示文字 progressbar.PercentView=true;//true顯示百分比(默認),false顯示詳細進度
如下顯示:

關於在數據綁定型控件中
有的時候每行的進度的最大值都是不同的,而在進度到達某一范圍需要顯示不同的樣式.這里我們就需要手動去設置數據對應我們預先定義好的RepositoryItemProgressBar
下面是一個簡單例子:
View Code
1 public partial class Form1 : Form 2 { 3 public Form1() 4 { 5 InitializeComponent(); 6 this.Load += new EventHandler(Form_Load); 7 } 8 9 Timer timer = new Timer(); 10 RepositoryItemProgressBar progressbar = new RepositoryItemProgressBar(); 11 12 private void Form_Load(object sender, EventArgs e) 13 { 14 progressbar.LookAndFeel.UseDefaultLookAndFeel = false; 15 progressbar.ShowTitle = true; 16 //皮膚,這里使用的Dev自帶的幾款皮膚之一 17 progressbar.LookAndFeel.SkinName = "Money Twins"; 18 //progressbar.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Office2003; 19 20 InitData(); 21 timer.Interval = 100; 22 timer.Tick += new EventHandler(timer_Tick); 23 timer.Start(); 24 } 25 26 private void timer_Tick(object sender, EventArgs e) 27 { 28 objects.ForEach(x =>{ 29 if (x.Index < x.Count) x.Index++; 30 else x.Index = 0; 31 }); 32 this.gridControl.RefreshDataSource(); 33 } 34 35 private List<TestObject> objects = new List<TestObject>(); 36 37 public void InitData() 38 { 39 objects.Clear(); 40 objects.Add(new TestObject() { ID="A0001",Name="Francis",Count=100,Index=0}); 41 objects.Add(new TestObject() { ID = "A0002", Name = "Andy", Count = 1000, Index = 0 }); 42 objects.Add(new TestObject() { ID = "A0003", Name = "Tom", Count = 20, Index = 0 }); 43 objects.Add(new TestObject() { ID = "A0004", Name = "Achang", Count = 50, Index = 0 }); 44 this.gridControl.DataSource = objects; 45 this.gridView.Columns["Count"].Visible = false; 46 this.gridView.Columns["Index"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; 47 } 48 49 private void gridView_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) 50 { 51 if (e.Column.FieldName == "Index") 52 { 53 int count = (int)this.gridView.GetRowCellValue(e.RowHandle, "Count"); 54 int index = (int)e.CellValue; 55 progressbar.Maximum = count; 56 e.RepositoryItem = progressbar; 57 } 58 } 59 60 private void gridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) 61 { 62 if (e.Column.FieldName == "Index") 63 { 64 int count = (int)this.gridView.GetRowCellValue(e.RowHandle, "Count"); 65 int index = (int)e.CellValue; 66 e.DisplayText = string.Format("{0}/{1}",index,count); 67 } 68 } 69 } 70 71 public class TestObject 72 { 73 public string ID { get; set; } 74 public string Name { get; set; } 75 public int Count { get; set; } 76 public int Index { get; set; } 77 }
顯示效果如下:

下載地址如下: 進度條
