gpt4 book ai didi

c# - Winform C# Datagridview paint header

转载 作者:太空宇宙 更新时间:2023-11-03 18:11:34 27 4
gpt4 key购买 nike

我想使用 C# 在 Windows 窗体中自定义我的数据 GridView 。我想要做的是用我制作的渐变绘制数据网格标题:

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);
}
}

问题是 datagridviews 没有绘画事件,所以我不能使用它。有没有办法用渐变绘制标题?或者唯一的方法是选择一种背景色?

谢谢..

最佳答案

如果您指的是 Column Header,是的。在 CellPainting 事件

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

关于c# - Winform C# Datagridview paint header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14012475/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com