0

我有一个带有几列自定义绘制边框的网格。但是,当我们将自定义绘制的边框与普通(非自定义)列进行比较时,它就像稍微厚一点。因此,如果我们应用背面颜色,将像第 2 行第 1 列一样填充整个单元格。有没有办法删除这个厚度,以便自定义和非自定义单元格看起来相似。

块引用

在此处输入图像描述

代码如下:

private void uxGrid_CustomDrawCell(object sender, RowcellCustomDrawEventArgs e)
{
if(col==1)
{
DrawCellBorder(b,e.bounds);
}
}

private void DrawCellBorder(RowCellCustomDrawEventArgs e, int top, int left, int right, int bottom)
{

Brush b = Brushes.Red;

if(top ==1)
e.Graphics.Fillrectangle(b, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bound.Width,1));


if(right ==1)
e.Graphics.Fillrectangle(b, new Rectangle(e.Bounds.X.Right, e.Bounds.Y, 1, e.Bound.Height));


if(bottom ==1)
e.Graphics.Fillrectangle(b, new Rectangle(e.Bounds.X, e.Bounds.Bottom, e.Bound.Width,1));


if(left ==1)
e.Graphics.Fillrectangle(b, new Rectangle(e.Bounds.X, e.Bounds.Y, 1, e.Bounds.Height));

}
4

2 回答 2

2

我相信您可以使用以下代码:

void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e) {
    var cellBounds = ((DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo)e.Cell).Bounds;
    DrawCellBorder(e.Graphics, Brushes.Red, cellBounds, 1);
}
void DrawCellBorder(Graphics g, Brush borderBrush, Rectangle cellBounds, int borderThickness) {
    Rectangle innerRect = Rectangle.Inflate(cellBounds, -borderThickness,- borderThickness);
    g.ExcludeClip(innerRect);
    g.FillRectangle(borderBrush, cellBounds);
}

请注意,e.Bounds在 CustomDrawCell 事件处理程序中返回一个单元格内容矩形(不是整个单元格边界)。

于 2013-05-17T11:33:34.717 回答
0

我已经用这段代码完成了,希望它有所帮助:(适用于总计)

    `if (e.RowValueType == PivotGridValueType.Total)  
            {                         
         e.GraphicsCache.FillRectangle(new   LinearGradientBrush(e.Bounds,            Color.LightBlue, Color.Blue, LinearGradientMode.Vertical), e.Bounds);

                Rectangle innerRect = Rectangle.Inflate(e.Bounds, -3, -3);
                e.GraphicsCache.FillRectangle(new LinearGradientBrush(e.Bounds, Color.Blue,
                    Color.LightSkyBlue, LinearGradientMode.Vertical), innerRect);
                e.GraphicsCache.DrawString(e.DisplayText, e.Appearance.Font,
                    new SolidBrush(Color.White), innerRect, e.Appearance.GetStringFormat());
                e.Handled = true;
            }    '
于 2013-05-17T10:16:20.537 回答