我有一个几列的网格,其边框是自定义绘制的。但是,当我们将自定义绘制的边框与普通(非自定义)列进行比较时,它就像厚一点。因此,如果我们应用背面颜色,将填充整个单元格,如第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 :(得分: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事件处理程序中的单元格内容矩形(而不是整个单元格边界)。
答案 1 :(得分: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;
} '