zoukankan      html  css  js  c++  java
  • DEV gridView中加入加载条显示进度,必须为圆角型

    借鉴了冰封一夏的控件重绘与AlbinDevExpress GridControl 单元格添加进度条(ProgressBar)完成,特别感谢

    private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
            {
                if (e.Column.FieldName == "name")
                {
                    DrawProgressBar(e);
    
                    e.Handled = true;
    
                    DrawEditor(e); 
                } 
            }
    //解决单元格只显示数值,而不显示进度条,(当点击单元格时数值会消失),那么需要我们再来手动的编写一段代码用来处理当单元格触发时一些操作.
    private void DrawEditor(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
            {
                GridCellInfo cell = e.Cell as GridCellInfo;
                Point offset = cell.CellValueRect.Location;
                BaseEditPainter pb = cell.ViewInfo.Painter as BaseEditPainter;
                AppearanceObject style = cell.ViewInfo.PaintAppearance;
                if (!offset.IsEmpty)
                    cell.ViewInfo.Offset(offset.X, offset.Y);
                try
                {
                    pb.Draw(new ControlGraphicsInfoArgs(cell.ViewInfo, e.Cache, cell.Bounds));
                }
                finally
                {
                    if(!offset.IsEmpty)
                    {
                        cell.ViewInfo.Offset(-offset.X, -offset.Y);
                    }
                }
            }
     /// <summary>
            /// 进度条绘制
            /// </summary>
            /// <param name="e"></param>
            public void DrawProgressBar(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
            {
                Rectangle rec = new Rectangle(e.Bounds.X + 327, e.Bounds.Y+15, (this.Width /3)+50, (this.Height-500)-10);
                Graphics g = e.Graphics;
                g. SetGDIHigh();           
                RectangleF m_lineRectangle = new RectangleF(rec.X, rec.Y, rec.Width - 10 * 2, 10);
                GraphicsPath pathLine = Retc.CreateRoundedRectanglePaths(m_lineRectangle, 5);
                g.FillPath(new SolidBrush(Color.FromArgb(30, 42, 58)), pathLine);
    
    
                //进度绘制
                string s = e.CellValue as string;
                string str = s; //s.Substring(0, e.CellValue.ToString().Length - 1);
                int ints = Convert.ToInt32(s);
                if (ints == 1)
                {
                    ints += 1;
                }//不然单纯的1进度有点丑
                decimal percent = Convert.ToDecimal(ints);
                int width = (int)(50 * Math.Abs(percent / 50) * e.Bounds.Width / 50);
                if (width >= rec.Width)
                {
                    width = rec.Width;
                }
                Rectangle rect = new Rectangle(e.Bounds.X + 327, e.Bounds.Y+15 , width, (this.Height - 500)-10);
                SolidBrush b = new SolidBrush(Color.FromArgb(0, 224, 24));
    
                if (percent > 20)
                {
                    b = new SolidBrush(Color.FromArgb(230, 0, 0));
                }
                else if (percent > 10)
                {
                    b = new SolidBrush(Color.FromArgb(254, 208, 0));
                }
                else if (percent == 0)
                {
                    b = new SolidBrush(Color.Transparent);
                }
                GraphicsPath valueLine = Retc.CreateRoundedRectanglePaths(new RectangleF(rect.X, rect.Y, width - 10 * 2, 10), 5);
    
                g.FillPath(b, valueLine);
    }
     public static GraphicsPath CreateRoundedRectanglePaths(this RectangleF rect, int cornerRadius)
            {
                GraphicsPath roundedRect = new GraphicsPath();
                roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
                roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
                roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
                roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
                roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
                roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
                roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
                roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
                roundedRect.CloseFigure();
                return roundedRect;
            }
  • 相关阅读:
    ORACLE 查看进程数,已执行任务数, 剩余任务数,删除指定任务
    ORACLE 收集统计整个用户数据
    解决Hystrix dashboard Turbine 一直 Loading…… 及其他坑
    利用 Maven 构造 Spring Cloud 微服务架构 模块使用 spring Boot构建
    AES加解密
    JAVA POI XSSFWorkbook导出扩展名为xlsx的Excel,附带weblogic 项目导出Excel文件错误的解决方案
    JAVA 文件的上传下载
    shell启停服务脚本模板
    JAVA 设计模式之 原型模式详解
    JAVA 设计模式之 工厂模式详解
  • 原文地址:https://www.cnblogs.com/xuezhu/p/12867710.html
Copyright © 2011-2022 走看看