解决 WinForm 中 TreeView 的 StateImageList 实际显示大小无法改变的问题
2009-07-09 16:00
721 查看
因为项目需要, 要更改 TreeView 的 StateImageList 大小, 试了下, 更改绑定的 StateImageList.ImageSize 没有作用, 显示大小始终是 16x16
在网上搜了搜, 相关资料比较少, 终于在 CodeProject 上找到问题原因:
http://www.codeproject.com/KB/tree/customstatetreeview.aspx?display=PrintAll&fid=313614&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=1519145
附文:
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);
}
在网上搜了搜, 相关资料比较少, 终于在 CodeProject 上找到问题原因:
http://www.codeproject.com/KB/tree/customstatetreeview.aspx?display=PrintAll&fid=313614&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=1519145
附文:
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);
}
相关文章推荐
- 解决 WinForm 中 TreeView 的 StateImageList 实际显示大小无法改变的问题 及 TreeView其他问题
- 解决TreeView的节点更改NodeFont后无法完全显示节点名的问题
- 父容器子容器大小设为百分比时,无法获取容器实际大小的问题的解决
- SenchaTouch2中list组件无法绑定存储或者绑定后仍旧无法显示数据问题解决
- 解决eclipse中Android SDK Manager更新慢和部分无法显示System Image镜像问题
- 解决在List中用Bitmap作Image的source时候无法正常显示的方法
- 解决WinForm中ComboBox控件的“设置"DataSourse”属性后无法修改项集合”以及两个不相关联的ComboxBox控件实现数据列表显示不可实现的问题
- 解决嵌入WinForm的WPF控件无法显示图片问题
- Visual Studio 2008项目中WinForm窗体图标显示为类图标,只能打开代码而无法打开视图问题解决
- Visual Studio 2008项目中WinForm窗口图标显示为类图标,仅仅能打开代码而无法打开视图问题解决
- Visual Studio 2008项目中WinForm窗体图标显示为类图标,只能打开代码而无法打开视图问题解决
- 自绘MFC List Control列表控件时无法改变表头CHeaderCtrl高度问题的解决方法
- 解决字体大小的改变影像显示对话框大小的问题
- 解决新版本Chrome无法显示border-image问题
- 解决关于图片大小不一导致Cell的imageView无法显示为圆形
- ImageView 无法显示图片问题解决办法
- PIL在windwos系统下Image.show无法显示图片问题的解决方法
- 解决Myeclipse在调试(debug)时无法显示变量值问题
- 解决在Linuxmint18.1环境下fcitx无法显示候选框的问题
- 解决html5 + js开发APP无法显示SVG问题(转化成canvas)