问题是,一旦将 SmallImageList 设置为 imgList1,它就永远不会 即使 SmallImageList 设置为 null,也会“释放”图标间距。 无论是否有图标,项目的缩进始终相同。
有什么解决办法吗?
最佳答案
这是一件不寻常的事情,.NET ListView 包装器无法处理它。您可以尝试重新创建 native Windows 控件来重置它。不确定这会不会有副作用,你必须尝试一下。将新类添加到您的项目中并粘贴下面所示的代码。编译。从工具箱顶部放下新控件,替换原来的控件。
using System;
using System.Windows.Forms;
class MyListView : ListView {
public new ImageList SmallImageList {
get { return base.SmallImageList; }
set {
base.SmallImageList = value;
if (value == null && base.IsHandleCreated) this.RecreateHandle();
}
}
}
关于winforms - 如何删除 ListView 的 null SmallImageList 属性后的图标空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3187837/