开发者

Open Context Menu On Selected TreeView Node

开发者 https://www.devze.com 2023-02-15 03:34 出处:网络
What is the problem with this code ? Private Sub trvHeader_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles trvHeader.NodeMouseClick

What is the problem with this code ?

 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
          开发者_StackOverflow      Dim p As Point = New Point(e.X, e.Y)

                mnuRoot.Show(p)
            End If
        End Sub

the context menu does not open in right position.


The ContextMenuStrip.Show(Point) overload requires the point to be in screen coordinates. Fix:

 mnuRoot.Show(trvHeader, p)

or use Control.PointToScreen()

0

精彩评论

暂无评论...
验证码 换一张
取 消