在DataGridView列标签中删除多余的填充? [英] Remove extra padding in DataGridView column label?

查看:138
本文介绍了在DataGridView列标签中删除多余的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DataGridView ,我试图减小宽度,所以它显示我希望在我的形式。在减小 DataGridView 的大小时,我有问题删除列名中的额外填充。

I have a DataGridView that I am trying to reduce the width of so it displays how I wish in my form. I am having issues "removing" the extra padding in the column names when reducing the size of the DataGridView.

左侧是表,因为我最初有了它,我意识到我会喜欢它更小,所以我减少宽度。中心图像代表在文本包装到下一行之前列将最小的列。正确的图像是我想要的表的大小,我已经显示文本(px)将适合这个空格。

On the left is the table as I originally had it, I realized that I would like it smaller so I decreased its width. The center image represents the smallest the columns will go before the text wraps to the next line. The right image is the size I would like the table to be, I have shown that the text "(px)" will fit in the space.

我已经经历了所有的设置,我可以在设计师找到,没有找到任何帮助。有谁知道如何解决这个问题?

I have gone through all of the settings I can find in the designer and have not found anything to help. Does anyone know how to fix this?

推荐答案

这是我的例子。虽然它可能不是最好的解决方案,但工作。



我测量了 HeaderCell 的内容(Height(px))的确切宽度,并设置列的宽度与一些额外的填充(例如,9)。

Here is my example. Although it might not be the best solution but worked.

I measured the exact width of HeaderCell's content ("Height (px)") and set the column's width with some additional padding (For example, 9).

dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
dataGridView1.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;
Size textSize = TextRenderer.MeasureText(dataGridView1.Columns[0].HeaderText, dataGridView1.Font);
dataGridView1.Columns[0].Width = textSize.Width + 9; // Adding some padding

这篇关于在DataGridView列标签中删除多余的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆