How do I handle a right click on an object?

07-12-2006, 08:35 AM
I have a waveform graph and I'd like to give the user the option to clear the graph after right clicking it. I'd like for the message box to show up starting at the cursor. This would be useful for several other programming needs as well. If you have code for handling the check for the msgbox being off the screen that would be great, but not necessary.


07-12-2006, 11:17 AM
The graph control should have a MouseDown (and MouseUp) event. One of the properties of the "e" MouseEventsArgs object is Button. Just check to see if the Button equals the right mouse button (there's an enumeration). MsgBox may take x and y values, not sure.

07-13-2006, 01:55 PM
While one can specify a location using an input box, it does not appear to be possible with a msg box. How can one make a menu like you can generally see when you right click on say a Windows icon?

07-13-2006, 02:21 PM
You want the ContextMenu (or ContextMenuStrip in VB2005) control. Simply drop one onto your form, add the menu items just like you would for a main menu. There are two ways of displaying it: 1) if the graph control has a ContextMenu property, simply set this to the context menu you've created. 2) Using the graph's MouseUp event, call the Show method of context menu (you can pass the position where you'd like it to appear).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum