我知道这篇文章相当陈旧,但是,如果你找不到最好的选择,我有一个可能有用的博客文章,它涉及利用LVM_SETICONSPACING.
根据我的博客,
最初,您需要添加:
using System.Runtime.InteropServices;
Run Code Online (Sandbox Code Playgroud)
接下来,您需要导入DLL,以便可以使用SendMessage来修改ListView参数.
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
Run Code Online (Sandbox Code Playgroud)
完成后,创建以下两个函数:
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));
}
Run Code Online (Sandbox Code Playgroud)
然后使用该函数,只需传入ListView,然后设置值.在该示例中,64像素是图像宽度,32像素是我的水平间距/填充,100像素是图像高度,16像素是我的垂直间距/填充,并且两个参数都需要最少4个像素.
ListViewItem_SetSpacing(this.listView1, 64 + 32, 100 + 16);
Run Code Online (Sandbox Code Playgroud)