CTreeCtrl 树状控件显示展开和折叠的按钮“+/-”

让树状控件显示展开和折叠的按钮其实是很简单的,把 Style 设置成TVS_HASBUTTONS就可以了。不过你可能会发现根节点却没有展开折叠按钮,咋回事呢?折腾半天也没作用,还是看看MSDN的文档吧。

TVS_HASBUTTONS
Displays plus (+) and minus (-) buttons next to parent items. The user clicks the buttons to expand or collapse a parent item’s list of child items. To include buttons with items at the root of the tree view, TVS_LINESATROOT must also be specified.

呵呵,注意到了吧,最后一句,还需要 TVS_LINESATROOT。这就够了吗?再看看 TVS_LINESATROOT

TVS_LINESATROOT
Uses lines to link items at the root of the tree-view control. This value is ignored if TVS_HASLINES is not also specified.

如果 TVS_HASLINES 没有设置,那么 TVS_LINESATROOT将会被忽略,所以也别忘了 TVS_HASLINES。再看TVS_HASLINES。

TVS_HASLINES
Uses lines to show the hierarchy of items.

看来不需要其他的了,试一试,可以了吧。呵呵。

你可能感兴趣的:(CTreeCtrl)