Devexpress 进度条皮肤设置

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

   

  下面是一个简单例子:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form_Load);
}
Timer timer = new Timer();
RepositoryItemProgressBar progressbar = new RepositoryItemProgressBar();
private void Form_Load(object sender, EventArgs e)
{
progressbar.LookAndFeel.UseDefaultLookAndFeel = false;
progressbar.ShowTitle = true;
//皮肤,这里使用的Dev自带的几款皮肤之一
progressbar.LookAndFeel.SkinName = "Money Twins";
//progressbar.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Office2003;
InitData(); timer.Interval = 100;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
objects.ForEach(x =>
{
if (x.Index < x.Count) x.Index++;
else x.Index = 0;
});
this.gridControl.RefreshDataSource();
}
private List<TestObject> objects = new List<TestObject>();
public void InitData()
{
objects.Clear();
objects.Add(new TestObject() { ID = "A0001", Name = "Francis", Count = 100, Index = 0 });
objects.Add(new TestObject() { ID = "A0002", Name = "Andy", Count = 1000, Index = 0 });
objects.Add(new TestObject() { ID = "A0003", Name = "Tom", Count = 20, Index = 0 });
objects.Add(new TestObject() { ID = "A0004", Name = "Achang", Count = 50, Index = 0 });
this.gridControl.DataSource = objects;
this.gridView.Columns["Count"].Visible = false;
this.gridView.Columns["Index"].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
}
private void gridView_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{
if (e.Column.FieldName == "Index")
{
int count = (int)this.gridView.GetRowCellValue(e.RowHandle, "Count");
int index = (int)e.CellValue;
progressbar.Maximum = count;
e.RepositoryItem = progressbar;
}
}
private void gridView_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column.FieldName == "Index")
{
int count = (int)this.gridView.GetRowCellValue(e.RowHandle, "Count");
int index = (int)e.CellValue;
e.DisplayText = string.Format("{0}/{1}", index, count);
}
}
}
public class TestObject
{
public string ID { get; set; }
public string Name { get; set; }
public int Count { get; set; }
public int Index { get; set; }
}

   

  显示效果如下:

 


没有更多推荐了,返回首页