如何显示winform treeview拖放的上方/下方图标

时间:2012-06-20 07:55:06

标签: winforms drag-and-drop treeview

我想在放置目标位置突出显示(显示图标)。类似于在目标节点上方或下方显示图标的第三方控件,以显示目标位置的预览。

A sample screenshot is attached, where it show a line below the target node:

是否有任何示例或想法如何在winform treeview中完成?

1 个答案:

答案 0 :(得分:0)

我找不到我想要的内容,意味着无法显示目标节点上方或下方的图标但是,我设法允许用户使用以下解决方案在目标节点上方或下方添加节点:

Treeview drop事件提供有关drop是在目标节点的图像还是文本部分上的信息,可用于决定是否在上方或下方添加删除的节点。

Dim hTest As TreeViewHitTestInfo
Private Sub TreeView1_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver

     Dim pt As Point = CType(sender, TreeView).PointToClient(New Point(e.X, e.Y))
     hTest = TreeView1.HitTest(pt)

End Sub

Private Sub TreeView1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop

    If hTest IsNot Nothing AndAlso hTest.Location = TreeViewHitTestLocations.Image Then
    'Add Above
    Else
    'Add Below
    End If

End Sub