Foxtable(狐表)用户栏目专家坐堂 → 目录树光标停留节点突出显示


  共有2163人关注过本帖树形打印复制链接

主题:目录树光标停留节点突出显示

帅哥哟,离线,有人找我吗?
qaz17909
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:802 积分:9093 威望:0 精华:0 注册:2017/1/26 14:38:00
目录树光标停留节点突出显示  发帖心情 Post By:2018/1/23 10:32:00 [只看该作者]

当光标移动到目录树的某个节点上,该节点可以突出显示,例如颜色变化或凹凸,当光标离开后恢复原貌,用NodeMouseHover似乎离开后没有恢复

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/1/23 10:38:00 [只看该作者]


 回到顶部
帅哥哟,离线,有人找我吗?
qaz17909
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:802 积分:9093 威望:0 精华:0 注册:2017/1/26 14:38:00
  发帖心情 Post By:2018/1/23 10:51:00 [只看该作者]

版主可否详细点,是在哪个事件中设置?还有,我指的不是选中后显示,而是光标停留在节点上,未点击便突出显示

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:802 积分:9093 威望:0 精华:0 注册:2017/1/26 14:38:00
  发帖心情 Post By:2018/1/23 16:13:00 [只看该作者]

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

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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


 回到顶部