【问题标题】:Custom Draw cell thick border自定义绘制单元格粗边框
【发布时间】:2013-05-17 09:35:23
【问题描述】:

我有一个带有几列自定义绘制边框的网格。但是,当我们将自定义绘制的边框与普通(非自定义)列进行比较时,它会稍微厚一些。因此,如果我们应用背景颜色,将像第 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));

}

【问题讨论】:

  • 我相信这个问题的原因在于您的“自定义绘图”代码。您能否将此代码附加到原始问题中?

标签: devexpress xtragrid


【解决方案1】:

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

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

【讨论】:

  • 那是完美的。谢谢 Dmirty,感谢您宝贵的时间和建议。
【解决方案2】:

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

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

【讨论】:

  • 我根据我的要求检查了这段代码。这也没有完全填充矩形。
  • 尝试像这样设置边界:(e.Bounds, 0, 0)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-28
  • 1970-01-01
  • 2011-05-04
相关资源
最近更新 更多