在选定的TreeView节点上打开上下文菜单

时间:2011-03-03 18:40:48

标签: .net treeview contextmenu

此代码有什么问题?

 Private Sub trvHeader_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles trvHeader.NodeMouseClick
            If e.Button = Windows.Forms.MouseButtons.Right Then
                trvHeader.SelectedNode = e.Node
                Dim p As Point = New Point(e.X, e.Y)

                mnuRoot.Show(p)
            End If
        End Sub

上下文菜单无法在正确的位置打开。

1 个答案:

答案 0 :(得分:1)

ContextMenuStrip.Show(Point)重载要求该点位于屏幕坐标中。修正:

 mnuRoot.Show(trvHeader, p)

或使用Control.PointToScreen()