gpt4 book ai didi

c# - 如何在 C# winforms 中设置自定义 DataGridView 边框

转载 作者:行者123 更新时间:2023-12-02 20:31:18 24 4
gpt4 key购买 nike

如果任何机构可以帮助我想用下面的单虚线打印 datagridview 标题行,我就会陷入困境,例如:

Name              ID
---------------------

并像这样打印没有任何边框的项目

Name              ID
---------------------
Abc 21

我使用了这段代码

dgvmain.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
dgvmain.CellBorderStyle = DataGridViewCellBorderStyle.None;

其中dgvmain是我的DataGridView的名称如有任何帮助,请提前致谢。

最佳答案

您需要通过向 CellPainting 事件处理程序添加代码来进行一些自定义绘制。要将单元格边框设置为 None,请使用 CellBorderStyle:

dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

// CellPainting event handler for your dataGridView1
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex > -1)
{
e.Handled = true;
using (Brush b = new SolidBrush(dataGridView1.DefaultCellStyle.BackColor))
{
e.Graphics.FillRectangle(b, e.CellBounds);
}
using (Pen p = new Pen(Brushes.Black))
{
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawLine(p, new Point(0, e.CellBounds.Bottom-1), new Point(e.CellBounds.Right, e.CellBounds.Bottom-1));
}
e.PaintContent(e.ClipBounds);
}
}

enter image description here

关于c# - 如何在 C# winforms 中设置自定义 DataGridView 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18297083/

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