似乎没有一种方法可以更改.NET ListView中所有行的填充(或行高)。有没有人有一套优雅的套路?
发布于 2012-10-25 23:51:38
我知道这篇文章很老了,但是,如果你从来没有找到最好的选择,我有一个可能会有帮助的blog post,它涉及到使用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);发布于 2008-09-12 00:03:40
一种解决方法是使用与您想要的项目高度一样高的ImageList。只需用背景颜色填充空白图像即可。您甚至可以将图像设置为1宽,以便不会在水平方向上占用太多空间。
https://stackoverflow.com/questions/57849
复制相似问题