문제

I have a grid with few columns with its borders custom drawn. But when we compare the borders of the custom drawn with the normal(non customised) columns it is like little thicker. So if we apply back color, will fill the whole cell like in Row number 2, Column 1. Is there any way to remove this thickness so that customised and non customised cells should look similar.

Blockquote

enter image description here

The code is as follows:

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));

}
도움이 되었습니까?

해결책

I beieve you can use the following code:

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);
}

Note that e.Bounds returns a cell content rectangle within the CustomDrawCell event handler (not the entire cell bounds).

다른 팁

I've done it with this code, hope it helps: (Works for Totals)

    `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;
            }    '
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top