【发布时间】:2019-07-22 09:37:48
【问题描述】:
我有一个 datagridview 控件,我想在每个标题单元格的底部放置一条 3px 的线,看起来像
我已经在 CellPainting 中添加了代码,甚至是 datagridview 的代码,例如:
if (e.RowIndex < 0) // headers
{
Rectangle newRect = new Rectangle(e.CellBounds.X, e.CellBounds.Y - 1 + e.CellBounds.Height, e.CellBounds.Width, 2);
using (Brush gridBrush = new SolidBrush(Color.Red))
{
e.Graphics.FillRectangle(gridBrush, newRect);
}e.Handled = true;
}
红线显示正确(我稍后会添加 3px)。但是,现在缺少标题文本。
我假设设置 e.Handled = true;告诉不要继续绘制原始标题文本。如果我将其设置为 false,那么红线就会消失。这个控件没有 base.CellPainting 类型的概念(显然)。
我知道我可以自己绘制文本,但是我不得不担心对齐、字体...
现在有没有办法告诉系统同时绘制行和绘制原始标题文本?
如有必要,我愿意尝试其他方法。
【问题讨论】:
-
在
e.Handled = true;之前添加e.PaintContent(e.CellBounds);!还要在您自己的绘图前添加e.PaintBackground(e.CellBounds, true);以获得单元格分隔符!
标签: c# winforms datagridview