cmdolcet
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
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.Wi ndows.Form s.Control. MousePosit ion))
SearchContextMenu.Show(Me.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.Mouse EventArgs gives the mouse location in client co-ordinates
With this line of code
SearchContextMenu.Show(Me.
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.