以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  目录树光标停留节点突出显示  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=113786)

--  作者:qaz17909
--  发布时间:2018/1/23 10:32:00
--  目录树光标停留节点突出显示
当光标移动到目录树的某个节点上,该节点可以突出显示,例如颜色变化或凹凸,当光标离开后恢复原貌,用NodeMouseHover似乎离开后没有恢复
--  作者:有点甜
--  发布时间:2018/1/23 10:38:00
--  

参考

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=44083&skin=0

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=83890&skin=0

 


--  作者:qaz17909
--  发布时间:2018/1/23 10:51:00
--  
版主可否详细点,是在哪个事件中设置?还有,我指的不是选中后显示,而是光标停留在节点上,未点击便突出显示

--  作者:有点甜
--  发布时间:2018/1/23 11:18:00
--  

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
    End If
End If
pnd = nd


--  作者:qaz17909
--  发布时间:2018/1/23 16:13:00
--  
效果出来了,但有个问题,就是我现在只有点击节点的图标有效,点击节点的文本时候无效,我是在NodeMouseClick编辑代码,这是怎么回事?
[此贴子已经被作者于2018/1/23 16:26:53编辑过]

--  作者:有点甜
--  发布时间:2018/1/23 16:45:00
--  

你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