.NET ListView行填充

似乎没有办法更改.NET ListView中所有行的填充(或行高)。 有没有人有一个优雅的黑客?

我知道这篇文章相当陈旧,但是,如果你找不到最好的选择,我有一个可能有用的博客文章 ,它涉及利用LVM_SETICONSPACING。

根据我的博客,

最初,您需要添加:

using System.Runtime.InteropServices; 

接下来,您需要导入DLL,以便可以使用SendMessage来修改ListView参数。

 [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); 

完成后,创建以下两个函数:

 public int MakeLong(short lowPart, short highPart) { return (int)(((ushort)lowPart) | (uint)(highPart << 16)); } public void ListViewItem_SetSpacing(ListView listview, short leftPadding, short topPadding) { const int LVM_FIRST = 0x1000; const int LVM_SETICONSPACING = LVM_FIRST + 53; SendMessage(listview.Handle, LVM_SETICONSPACING, IntPtr.Zero, (IntPtr)MakeLong(leftPadding, topPadding)); } 

然后使用该函数,只需传入ListView,然后设置值。 在该示例中,64像素是图像宽度,32像素是我的水平间距/填充,100像素是图像高度,16像素是我的垂直间距/填充,并且两个参数都需要最少4个像素。

 ListViewItem_SetSpacing(this.listView1, 64 + 32, 100 + 16); 

解决方法是使用与您想要的项目一样高的ImageList。 只需用背景颜色填充空白图像即可。 您甚至可以将图像放宽1,以免水平占用太多空间。