如何向单个 TreeView 项目添加多个图标?

发布于 2024-10-31 15:23:13 字数 518 浏览 5 评论 0原文

我试图向 Treeview 项目显示多个图标,但它没有显示所有图标,它只显示一个。 我正在使用以下代码:

CImageList m_imageState;
m_cTree.m_imageState.Create(16, 16, ILC_MASK, 0, 4);
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm2, RGB(255,0,255));
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm1, RGB(0,255,255));
m_cTree.SetImageList( &(m_cTree.m_imageState), TVSIL_NORMAL ); 

但是当我看到 Treeview 时,项目仅显示一个图标。 是否可以使用 Treeview 项目显示多个图标?

请建议我该怎么做。

I am trying to display multiple icons to the Treeview item but it is not displaying all the icons, it displays only one.
I am using the following code:

CImageList m_imageState;
m_cTree.m_imageState.Create(16, 16, ILC_MASK, 0, 4);
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm2, RGB(255,0,255));
m_cTree.m_imageState.Add(&bm, RGB(255,255,0));
m_cTree.m_imageState.Add(&bm1, RGB(0,255,255));
m_cTree.SetImageList( &(m_cTree.m_imageState), TVSIL_NORMAL ); 

But when I see Treeview, item displays only one icon.
Is it possible to display multiple icons with Treeview item?

Please suggest how can I do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韵柒 2024-11-07 15:23:13

正确,TreeView 控件中的每一项仅显示一个图标。这是设计使然,是 MFC 库包装的本机控件的硬限制。

能够为每个项目显示多个图标的唯一方法是所有者绘图。对于 TreeView 控件来说,这是一项相当困难的任务,远不如所有者绘制按钮或标签控件那么容易。确保您确实需要此功能,并考虑是否有更好的方式向用户显示相关信息。

或者,您可以创建将多个图像相邻组合的自定义位图,并将这些图像添加到您的 ImageList 中。生成的图像将比高度宽,但控件并不关心:只要图像列表中的所有图像具有相同的尺寸,它就会显示您指定的任何尺寸的图像。这绝对是一种黑客攻击,但它可能会起作用,具体取决于您的需求。

Correct, only one icon will be displayed per item in a TreeView control. This is by design, a hard limitation of the native control that the MFC library wraps.

The only way you're going to be able to display multiple icons per item is owner drawing. It's a pretty difficult task for a TreeView control, not nearly as easy as owner drawing a button or a label control. Make sure that you really this need this functionality, and consider whether there's a better way of displaying the relevant information to your users.

Alternatively, you could create custom bitmaps that combine multiple images next to one another, and add those to your ImageList. The resulting images will be wider than they are tall, but the control doesn't care: it will display whatever size images you specify, as long as all the images in the image list have the same dimensions. This is definitely a hack, but it might work, depending on your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文