Prevent contextmenustrip from opening

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I have a form and i set a contextmenustrip to it. Then i added a picturebox to the form. Can i make it so that if i right click the picturebox the form's contextmenustip doesnt open? Can i just prevent it from opening instead of giving it another contextmenustrip?
 
I have never been in a position where it's an issue but it appears that child controls inherit their parent's ContextMenuStrip implicitly unless you you explicitly set it otherwise to something other than Nothing. It seems like a bit of a hack but this is the best method I can come up with to do what you want:
Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
    e.Cancel = Me.RectangleToScreen(Me.PictureBox1.Bounds).Contains(Control.MousePosition)
End Sub
 
Back
Top