• 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;
            }
  • 相关阅读:
    VS2013 更新系统.net framework4.8引起的datagridview添加列弹框的显示问题
    IIS发布获取apk文件,部署IIS遇到的问题记录
    C# winform 动态构建fastreport报表
    其他信息: 未能加载文件或程序集“WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。找 到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
    winform DataGridView的虚模式填充,CellValueNeeded事件的触发条件
    winform中的小技巧【自用】
    仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'XXX'中的标识列指定显式值。
    VS 2013Ultimate 开发过程中遇到的问题——listbox的隐藏问题,combobox.textchanged的中文问题
    AFO
    几个救了我命的小不等式
  • 原文地址:https://www.cnblogs.com/xuezhu/p/12867710.html
Copyright © 2020-2023  润新知