Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

asked on

VB Context menu and control set

I am trying to set me context menu right click location to open whenever the user clicks on my control (Me.GridSpread). It always seem to open on right click of the context control itself on the upper menu button area.

Private Sub frmSearch_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then
            SearchContextMenu.Show(Me.GridSpread, New System.Drawing.Point(0, 200))
        End If
    End Sub

Open in new window

Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

See: https://msdn.microsoft.com/en-us/library/s00cc2f3(v=vs.110).aspx

With this line of code
SearchContextMenu.Show(Me.GridSpread, New System.Drawing.Point(0, 200))
you display the context menu at the point 0,200 - ALWAYS.  In other words it is working as you have coded it to work.

You might also want to look at:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseposition(v=vs.110).aspx
which shows you where the mouse is on a control.  At a guess you are wanting that.
Avatar of cmdolcet

ASKER

Yes I agree displaying it works fine, however to activate that display on the event of the right mouse click is not on the gridSpread but where the context menu is place on the screen in the IDE.
Then something like this:
SearchContextMenu.Show(Me.GridSpread, Me.PointToClient(System.Windows.Forms.Control.MousePosition))
OK great that shows up on the grid... However I want to be able to initiate it when when I right click on the gird, that is what I ultimately want. Right now it is initiated on the top of the form where the actual control sits.
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Andy would the "Me, New Point(e.X, e.Y)" as new point help solve this issue as to where the Right click is made?
because the ByVal e As System.Windows.Forms.MouseEventArgs gives the mouse location in client co-ordinates