你nodemouseclick事件的代码,写到afterSelectNode事件去,然后
全局代码
Public Sub lbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
sender.parent.selectedNode = sender.tag
End Sub
mousemove事件
'static ptime As Date = Nothing
'Dim sp As TimeSpan = Date.now - ptime
'ptime = Date.now
'If sp.TotalMilliseconds < 50 Then '间隔1000毫秒
'Return
'End If
static pnd As object
Dim tree As windows.Forms.treeview = e.sender.basecontrol
Dim x As Integer = System.Windows.Forms.Cursor.Current.Position.X
Dim y As Integer = System.Windows.Forms.Cursor.Current.Position.Y
Dim pt = tree.PointToClient(new Point(X, Y)) '取当前坐标
Dim nd As System.Windows.Forms.TreeNode = tree.GetNodeAt(pt) '取坐标所在位置的节点
If nd Is Nothing OrElse pnd Is Nothing OrElse pnd.name <> nd.name Then
For i As Integer = tree.Controls.Count - 1 To 0 Step -1
If tree.Controls(i).Name = "SelectLab" Then
tree.Controls.RemoveAt(i)
End If
Next
If nd IsNot Nothing
Dim selCon As System.Windows.Forms.Control = tree.Controls("SelectLab")
Dim label As New System.Windows.Forms.Label
label.Name = "SelectLab"
label.AutoSize = False
label.BackColor = Color.Red
label.ForeColor = nd.ForeColor
label.Font = new font(tree.Font.name, tree.Font.size, FontStyle.Bold )
tree.Controls.Add(label)
selCon = Label
Dim node As System.Windows.Forms.TreeNode = nd
selCon.Size = new Size(node.Bounds.Width+5, node.Bounds.Height)
selCon.Location = new Point(node.Bounds.X, node.Bounds.Y)
selCon.Text = nd.Text
selCon.tag = nd
AddHandler selCon.Click, AddressOf lbl_Click
End If
End If
pnd = nd