• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Context menu in VB.NET issue

SoftwareEng

Senior member
Guys,

I need to display a context menu (ContextMenuStrip) directly below the control that was clicked, e.g. a Button. I don't care about the exact mouse coordinates. How can I pop up a menu at the clicked control's lower-left corner?

thanks!
 
Is your issue that it's showing up in the wrong location? If you use an event like MouseUp (which you should since almost every app does it there instead of MouseDown), the coordinates should already be in screen coordinates. If they're not, you could try calling PointToScreen off the button and pass in the coordinates. I'm working off of memory here, but if the Show() method of the context menu takes a control *and* a point, the point will be relative to the control itself, so you'd have to call PointToClient on the points given to you.
 
Originally posted by: Tencntraze
Is your issue that it's showing up in the wrong location? If you use an event like MouseUp (which you should since almost every app does it there instead of MouseDown), the coordinates should already be in screen coordinates. If they're not, you could try calling PointToScreen off the button and pass in the coordinates. I'm working off of memory here, but if the Show() method of the context menu takes a control *and* a point, the point will be relative to the control itself, so you'd have to call PointToClient on the points given to you.

But I don't care about the mouse coordinates. The menu must be shown in the same place (directly below the Button control), no matter where exactly the user clicked.....
 
ok, well then why not just take the Location + Height of the button as the mouse points and apply my previous statement with that?
 
Originally posted by: Tencntraze
ok, well then why not just take the Location + Height of the button as the mouse points and apply my previous statement with that?

because then the menu shows up in some weird place outside of the form itself 😉 these must be relative to the container (Frame), which own coordinates are relative to its container, so I'd have to do massive calcs to compute the screen coordinates 🙁
 
Now that I had a computer to test it, just try

Me.ContextMenuStrip1.Show(Me.Button1, New Point(0, Me.Button1.Height))

The point is relative to the specified control's location, so if you want it to show right below the button, you just provide a positive Y value as such.
 
Originally posted by: Tencntraze
Now that I had a computer to test it, just try

Me.ContextMenuStrip1.Show(Me.Button1, New Point(0, Me.Button1.Height))

The point is relative to the specified control's location, so if you want it to show right below the button, you just provide a positive Y value as such.

brilliant, it works 🙂 thank you sir!
 
Back
Top