请高手帮忙解释一下这段VB小程序 25
PrivateSubFORM_Load()DimiAsIntegerTreeView1.Style=tvwTreelinesPlusMinusPictureTextFor...
Private Sub FORM_Load()
Dim i As Integer
TreeView1.Style = tvwTreelinesPlusMinusPictureText
For i = 1 To 20
TreeView1.Nodes.Add , , "Node" & i, "Node " & i
Next i
TreeView1.HideSelection = False
TreeView1.LabelEdit = tvwManual
End Sub
Private Sub MenuNodesNodeX_Click()
VBA.MsgBox "Node: [" & MenuNodesNodeX.Caption & "] Pop End Sub
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
If TreeView1.HitTest(x, y) Is TreeView1.SelectedItem Then
If Not TreeView1.SelectedItem Is Nothing Then
MenuNodesNodeX.Caption = TreeView1.SelectedItem.Text
Me.PopupMenu MenuNodes
End If
End If
End If
End Sub
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Not TreeView1.HitTest(x, y) Is TreeView1.SelectedItem Then
Set TreeView1.SelectedItem = Nothing
End If
End Sub 展开
Dim i As Integer
TreeView1.Style = tvwTreelinesPlusMinusPictureText
For i = 1 To 20
TreeView1.Nodes.Add , , "Node" & i, "Node " & i
Next i
TreeView1.HideSelection = False
TreeView1.LabelEdit = tvwManual
End Sub
Private Sub MenuNodesNodeX_Click()
VBA.MsgBox "Node: [" & MenuNodesNodeX.Caption & "] Pop End Sub
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbRightButton Then
If TreeView1.HitTest(x, y) Is TreeView1.SelectedItem Then
If Not TreeView1.SelectedItem Is Nothing Then
MenuNodesNodeX.Caption = TreeView1.SelectedItem.Text
Me.PopupMenu MenuNodes
End If
End If
End If
End Sub
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Not TreeView1.HitTest(x, y) Is TreeView1.SelectedItem Then
Set TreeView1.SelectedItem = Nothing
End If
End Sub 展开
展开全部
这个代码主要功能,就是右键点击某一节点,就会弹出一个菜单
Private Sub FORM_Load()
Dim i As Integer '定义一个整型变量
TreeView1.Style = tvwTreelinesPlusMinusPictureText '设置显示样式
For i = 1 To 20
TreeView1.Nodes.Add , , "Node" & i, "Node " & i '添加20个节点
Next i
TreeView1.HideSelection = False '决定当控件失去焦点时选择文本是否加亮显示
TreeView1.LabelEdit = tvwManual '对标签编辑的设置
End Sub
Private Sub MenuNodesNodeX_Click()
VBA.MsgBox "Node: [" & MenuNodesNodeX.Caption & "] Pop " '这段我不清楚,好象是菜单相关的一点代码
End Sub
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) '鼠标按键弹起时
If Button = vbRightButton Then '如果是右键
If TreeView1.HitTest(x, y) Is TreeView1.SelectedItem Then '如果按下的标签是已被选中的标签
If Not TreeView1.SelectedItem Is Nothing Then '如果控件中确实有节点被选中
MenuNodesNodeX.Caption = TreeView1.SelectedItem.Text '就把选中的节点文字写到MenuNodesNodeX.Caption里去,是菜单吗?不清楚
Me.PopupMenu MenuNodes '弹出菜单
End If
End If
End If
End Sub
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Not TreeView1.HitTest(x, y) Is TreeView1.SelectedItem Then '如果按下的标签不是已被选中的标签
Set TreeView1.SelectedItem = Nothing '就设置它为没有,这个做用是只能对已选中的项目进行拖放
End If
End Sub
Private Sub FORM_Load()
Dim i As Integer '定义一个整型变量
TreeView1.Style = tvwTreelinesPlusMinusPictureText '设置显示样式
For i = 1 To 20
TreeView1.Nodes.Add , , "Node" & i, "Node " & i '添加20个节点
Next i
TreeView1.HideSelection = False '决定当控件失去焦点时选择文本是否加亮显示
TreeView1.LabelEdit = tvwManual '对标签编辑的设置
End Sub
Private Sub MenuNodesNodeX_Click()
VBA.MsgBox "Node: [" & MenuNodesNodeX.Caption & "] Pop " '这段我不清楚,好象是菜单相关的一点代码
End Sub
Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) '鼠标按键弹起时
If Button = vbRightButton Then '如果是右键
If TreeView1.HitTest(x, y) Is TreeView1.SelectedItem Then '如果按下的标签是已被选中的标签
If Not TreeView1.SelectedItem Is Nothing Then '如果控件中确实有节点被选中
MenuNodesNodeX.Caption = TreeView1.SelectedItem.Text '就把选中的节点文字写到MenuNodesNodeX.Caption里去,是菜单吗?不清楚
Me.PopupMenu MenuNodes '弹出菜单
End If
End If
End If
End Sub
Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Not TreeView1.HitTest(x, y) Is TreeView1.SelectedItem Then '如果按下的标签不是已被选中的标签
Set TreeView1.SelectedItem = Nothing '就设置它为没有,这个做用是只能对已选中的项目进行拖放
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询