[英]Winform C# Datagridview paint header
I want to customize my datagridviews in windows forms using c#.我想使用 c# 在 windows 窗体中自定义我的 datagridviews。 What I want to do is to Paint the datagrid header with a gradient I made:我想要做的是用我制作的渐变绘制数据网格标题:
public void Colorear_Barra_abajo(object sender, PaintEventArgs e)
{
Rectangle r = new Rectangle(0,0, panel_Borde_abajo.Width, panel_Borde_abajo.Height);
if (r.Width > 0 && r.Height > 0)
{
Color c1 = Color.FromArgb(255, 54, 54, 54);
Color c2 = Color.FromArgb(255, 62, 62, 62);
Color c3 = Color.FromArgb(255, 98, 98, 98);
LinearGradientBrush br = new LinearGradientBrush(r, c1, c3, 90, true);
ColorBlend cb = new ColorBlend();
cb.Positions = new[] { 0, (float)0.5, 1 };
cb.Colors = new[] { c1, c2 , c3 };
br.InterpolationColors = cb;
// paint
e.Graphics.FillRectangle(br, r);
}
}
The issue is that datagridviews does not have paint event so i can´t use this.问题是 datagridviews 没有绘制事件,所以我不能使用它。 Is there any way to paint the header with a gradient?有没有办法用渐变绘制标题? Or the only way is to select one backcolor?或者唯一的方法是选择一种背景色?
Thanks..谢谢..
If you mean Column Header
, yes.如果您的意思是Column Header
,是的。 in the CellPainting Event
在CellPainting Event
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1)
{
Color c1 = Color.FromArgb(255, 54, 54, 54);
Color c2 = Color.FromArgb(255, 62, 62, 62);
Color c3 = Color.FromArgb(255, 98, 98, 98);
LinearGradientBrush br = new LinearGradientBrush(e.CellBounds, c1, c3, 90, true);
ColorBlend cb = new ColorBlend();
cb.Positions = new[] { 0, (float)0.5, 1 };
cb.Colors = new[] { c1, c2, c3 };
br.InterpolationColors = cb;
e.Graphics.FillRectangle(br, e.CellBounds);
e.PaintContent(e.ClipBounds);
e.Handled = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.