2013-05-17 37 views
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)); 

} 
+0

我相信这个问题的原因是在你的“自定义绘制”代码。你能把这段代码追加到原来的问题吗? – DmitryG

+0

代码更新。 – 17CrazyBrain

回答

2

我beieve你可以使用下面的代码:

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事件处理程序内的单元格内容矩形(不是整个小区边界)。

+0

这就是最完美的一个。谢谢你,为你提供宝贵的时间和建议。 – 17CrazyBrain

0

我这个代码做了它,希望它有助于:(Works的总计)

`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; 
      } ' 
+0

我用我的要求检查了这个代码。这也不能完全填充矩形。 – 17CrazyBrain

+0

尝试设置像这样的界限:(e.Bounds,0,0) – Milen

+0

感谢Milen ..但它没有按我期望的方式工作 – 17CrazyBrain

相关问题