Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I get a Contextmenu on Right click the picture box in windows application.The same contextmenu has to display for all the picture boxes.
Posted
Updated 23-Jan-17 4:34am
v2

try this..

pictureBox1.ContextMenustrip=contextMenuStrip1;
 
Share this answer
 
This isn't that hard, but easy to forget.
For example, lets say you have a picture box, and you have drawn things on it and want the user to be able to have a context menu for when a thing is selected and a different one when not selected. You could assign the picture box the context menu as things are selected / not selected. Or you could do it on the right click show them menu.
I'm showing that second thing here because I find it less error prone when maintaining, just my personal choice.

In either case you'd create a context menu object, fill it in, create the handlers, etc.

C#
if (e.Button == MouseButtons.Right)
{
    mPointWhenClicked = new Point(e.X, e.Y);
    if (mObjectAlreadySelectedInImage != null)
    {
        contextMenuWhenSelected.Show(pictureBox1, e.X, e.Y);
    }
    else
    {
        contextMenuWhenNotSelected.Show(pictureBox1, e.X, e.Y);
    }
}
 
Share this answer
 
Comments
Richard Deeming 23-Jan-17 14:40pm    
You really need to buy a calendar!

Your first QA answer[^] was to an already-answered question from five years ago.

This, your second answer, is to an already-answered question from nearly 5 ½ years ago!

Please stop resurrecting ancient questions which have already been answered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900