因为项目需要, 要更改 TreeView 的 StateImageList 大小, 试了下, 更改绑定的 StateImageList.ImageSize 没有作用, 显示大小始终是 16x16
在网上搜了搜, 相关资料比较少, 终于在 CodeProject 上找到问题原因:
附文:
Underlying comctl treeview uses a zero image index, indicating no state image is displayed.
Thus comctl state imagelist must have a dummy as first image.
.NET copies the passed StateImageList to a new NET internal imagelist.
The first image is duplicated, serving as dummy and the copy is passed to comctl.
TreeNode.StateImageIndex values passed to comctl are then increased by 1.
This might have been a nice feature, but WinForms Team blundered using a constant 16 x 16 size for the copy.
If you want different size, use code below and add a dummy as first image.
// in derived TreeView
protected override void WndProc(ref Message m)
{
const int TV_FIRST = 0x1100;
const int TVM_SETIMAGELIST = (TV_FIRST + 9);
const int TVSIL_STATE = 2;
if (m.Msg == TVM_SETIMAGELIST)
{
if (m.WParam.ToInt32() == TVSIL_STATE &&
m.LParam != IntPtr.Zero)
{
// NET assigns a copy of StateImageList
Debug.Assert(StateImageList != null);
// pass comctl the original
m.LParam = StateImageList.Handle;
}
}
base.WndProc(ref m);
}
本文介绍了如何解决TreeView控件中StateImageList显示大小固定为16x16的问题,并提供了一个通过重写WndProc方法来传递原始StateImageList的解决方案。
2336

被折叠的 条评论
为什么被折叠?



