【发布时间】:2016-06-09 17:14:03
【问题描述】:
现在我已将代码转换为自定义DataGridView Column 和 Cell,我有一个 Paint 中不可用的属性strong> 事件:
class DataGridViewColourComboBoxCell : DataGridViewComboBoxCell
{
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
//base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
Rectangle rDraw;
rDraw = Rectangle.FromLTRB(cellBounds.Left, cellBounds.Top, cellBounds.Right, cellBounds.Bottom - 1);
//Pen penGridlines = new Pen(dataGridView.GridColor);
graphics.DrawRectangle(Pens.Black, rDraw);
//penGridlines.Dispose();
}
}
当我在 DVG 中使用 CellPainting 事件时,我可以使用:
Pen penGridlines = new Pen(dataGridView.GridColor);
g.DrawRectangle(Pens.Black, rDraw);
penGridlines.Dispose();
但我不知道如何访问DataGridView 对象,以便获得GridColor 属性值。
更新:
我在这里找到:https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.gridcolor%28v=vs.110%29.aspx 网格线的默认颜色是 SystemColors.ControlDarkDark。所以我现在有:
Pen penGridlines = new Pen(SystemColors.ControlDarkDark); // dataGridView.GridColor
graphics.DrawRectangle(penGridlines, rDraw);
graphics.FillRectangle(brBack, rDraw);
penGridlines.Dispose();
但我们可以在这种情况下使用GridColor 属性吗?
【问题讨论】:
标签: c# datagridview