We help IT Professionals succeed at work.

VB Context menu and control set

Last Modified: 2018-01-02
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

Watch Question

AndyAinscowFreelance programmer / Consultant

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:
which shows you where the mouse is on a control.  At a guess you are wanting that.


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.
AndyAinscowFreelance programmer / Consultant

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.
Freelance programmer / Consultant
This one is on us!
(Get your first solution completely free - no credit card required)


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?
AndyAinscowFreelance programmer / Consultant

because the ByVal e As System.Windows.Forms.MouseEventArgs gives the mouse location in client co-ordinates

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.