gpt4 book ai didi

c# - 从 DataGridView 单元格中删除填充/边距

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:30 25 4
gpt4 key购买 nike

我对 DataGridView 有疑问。默认单元格样式有一些边距或填充,使所有行都比我需要的高。

我将 RowTemplate 中的 Height 属性设置为较小的值(即 15 像素),但现在单元格将下划线 ('_') 等符号切掉,并且单元格顶部有 1 或 2 个空白像素。

如何使 DataGridView 单元格像 ListView(详细 View )一样显示没有填充/边距的值?

拉齐0_0

最佳答案

I am hoping that this goes some of the way to helping you in this situation;

void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)//remove padding
{
// ignore the column header and row header cells

if (e.RowIndex != -1 && e.ColumnIndex != -1)
{
e.PaintBackground(e.ClipBounds, true);
e.Graphics.DrawString(Convert.ToString(e.FormattedValue), e.CellStyle.Font, Brushes.Gray, e.CellBounds.X, e.CellBounds.Y - 2, StringFormat.GenericDefault)
e.Handled = true;
}
}

关于c# - 从 DataGridView 单元格中删除填充/边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5017046/

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