DevExpress GridControl 单元格添加进度条(ProgressBar) 首先可以使用DevExpress GridControl 自带的进度条控件.
Devexpress How to change progress bar control color Can someone tell me that how to change backcolor of progress bar control. I am using devexpress bar control. I have searched and tried the ways which are explained on devexpress forum and this site.progress bar back color
c# devexpress progress-bar devexpress-windows-ui
If ProgressBarControl.Property.LookAndFeel.Style
is set to Skin
, the control's background is fully controlled by the current skin. The progress bar appearance can be customized via the Properties.StartColor
and EndColor
properties. Change LookAndFeel
to anything except UseDefaultLookAndFeel
that will work.
【DevExpress GridControl 单元格添加进度条(ProgressBar)】
文章图片
但是我要用一个方法来设置所以的单元格进度,而不是每个单元格都要设置一遍,同时我想要根据进度值不同,进度条显示不同的颜色.
那么就要自己手动的编写代码来完成了.
1 : 绘制一个单元格进度条 形状当进度小于50%时显示为红色.
文章图片
1public void DrawProgressBar(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
2{
3string s = e.CellValue as string;
4s = s.Substring(0, e.CellValue.ToString().Length - 1);
5decimal percent = Convert.ToDecimal(s);
6int width = (int)(100 * Math.Abs(percent /100 ) * e.Bounds.Width / 100);
7Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, width, e.Bounds.Height);
8Brush b = Brushes.Green;
9if (percent < 50)
10{
11b = Brushes.Red;
12}
13e.Graphics.FillRectangle(b, rect);
14}
2 :点击 GridView 展开触发事件
1private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
2{
3if (e.Column.FieldName == "CLASSPACE")
4{
5DrawProgressBar(e);
6
7e.Handled = true;
8
9DrawEditor(e);
10}
11}
3 : 上面两段代码其实效果已经出来了,只不过有一些瑕疵,单元格只显示数值,而不显示进度条,(当点击单元格时数值会消失),那么需要我们再来手动的编写一段代码用来处理当单元格触发时一些操作.
代码:
1private void DrawEditor(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
2{
3GridCellInfo cell = e.Cell as GridCellInfo;
4Point offset = cell.CellValueRect.Location;
5BaseEditPainter pb = cell.ViewInfo.Painter as BaseEditPainter;
6AppearanceObject style = cell.ViewInfo.PaintAppearance;
7if (!offset.IsEmpty)
8cell.ViewInfo.Offset(offset.X, offset.Y);
9try
10{
11pb.Draw(new ControlGraphicsInfoArgs(cell.ViewInfo, e.Cache, cell.Bounds));
12}
13finally
14{
15if(!offset.IsEmpty)
16{
17cell.ViewInfo.Offset(-offset.X, -offset.Y);
18}
19}
20}
文章图片
同时 将 单元格设置为不可编辑状态.
附 最后显示效果 :
文章图片
作者:刘彬
出处:http://www.cnblogs.com/Albin/
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面
推荐阅读
- C#|C# 文件路径操作
- C# 接口实例
- C#|10、接口、抽象、密封、开放封闭原则
- c#|11、C#处理程序异常的技术
- C#|九、C#结构 类 属性
- C#|c# HashtableTo Json 字符串 HashtableToWxJson
- 分表分库(百亿级大数据存储)
- C#|微信小程序开发系列(六)——“处理请求时出错”怎么处理()
- c#做的一个简单的包含实时进度的进度条
- asp.net|c#文件写入与获取post请求数据