问题描述
似乎没有要改变所有行填充(或行高)在.NET ListView中的一种方式。没有任何人有一个优雅的黑客绕?
There doesn't seem to be a way to change the padding (or row height) for all rows in a .NET ListView. Does anybody have an elegant hack-around?
推荐答案
我知道这个职位是相当老,但是,如果你没有找到最佳的选择,我有一个的,可以帮助,它涉及利用LVM_SETICONSPACING。
I know this post is fairly old, however, if you never found the best option, I've got a blog post that may help, it involves utilizing LVM_SETICONSPACING.
据我的博客,
首先,你需要添加:
using System.Runtime.InteropServices;
接下来,你需要导入的DLL,这样就可以利用SendMessage函数,修改ListView的参数。
Next, you'll need to import the DLL, so that you can utilize SendMessage, to modify the ListView parameters.
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
一旦完成,创建以下两个功能:
Once that is complete, create the following two functions:
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个像素。
Then to use the function, just pass in your ListView, and set the values. In the example, 64 pixels is the image width, and 32 pixels is my horizontal spacing/padding, 100 pixels is the image height, and 16 pixels is my vertical spacing/padding, and both parameters require a minimum of 4 pixels.
ListViewItem_SetSpacing(this.listView1, 64 + 32, 100 + 16);
这篇关于.NET ListView中排填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!