本文介绍了仅按节点图像展开/折叠TreeView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:doh:
我在表单上有一个包含很多项目/节点的TreeView.当我双击节点的一个项目时,我会运行一个过程(取决于所单击的项目).我的问题是,仅当我单击该节点的图标(+或-符号)时,我才希望它展开/折叠,如果我双击一个项目,则为

:doh:
I have on my form a TreeView with a lots of items/nodes. When I double click a item of a node I run a procedure (depending of the clicked item).My problem is that I want it to expand/collapse only when I click on the icon of the node ( the + or - sign), not if I double click an item

推荐答案

TreeNode trNode = (TreeNode)e.Node;
trNode.Collapse();



试试这个..

干杯:)



Try this..

Cheers:)


Private Sub tv1_NodeMouseClick(sender As Object, e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tv1.NodeMouseClick
  If e.X < e.Node.Bounds.Left Then
    Debug.Print("Img Click")
  Else
    Debug.Print("Txt Click")
  End If
End Sub



e.X是鼠标单击的X坐标(水平位置). e.Node.Bounds是节点文本的边界(左/右/高度/宽度).因此,如果X坐标小于节点文本边界的最左侧位置,则单击发生在节点的图像区域(左侧).



The e.X is the X-coordinate (horizontal position) of the mouse click. the e.Node.Bounds is the bounds (left/right/height/width) of the node text. So if the X coordinate is less than the node text bounds left-most position, the click occurred in the image area (to the left) of the node.


private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)


这篇关于仅按节点图像展开/折叠TreeView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 16:20