Popup Menu C#

AndyC1000
AndyC1000 used Ask the Experts™
on
Dear all,

I've been trying to create a pop-up menu on the mouse right click.  Then call an onClick event to call a method based on the selection.

The pop-up box isn't appearing with the items defined below even though the message box is recognising the right mouse button click.

  private void Chart_OnMouseDown(object sender, EventArgs e)
        {
               MouseEventArgs me = e as MouseEventArgs;

                if (me != null)
                {
                    if (me.Button == MouseButtons.Right)
                    {
                        MessageBox.Show("Right button selected");

                        ToolStripMenuItem mi_2 = new ToolStripMenuItem("Test1");
                        ToolStripMenuItem mi_3 = new ToolStripMenuItem("Test2");
                        ToolStripMenuItem mi_4 = new ToolStripMenuItem("Test3");

                        ContextMenuStrip contextMenu1 = new ContextMenuStrip();
                        contextMenu1.Items.Add(mi_2);
                        contextMenu1.Items.Add(mi_3);
                        contextMenu1.Items.Add(mi_4);
                  }
                }
        }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AndyAinscowFreelance programmer / Consultant

Commented:
Is that the complete code?

I don't see anything about showing or positioning the context menu for instance.
Luis PérezSoftware Architect in .Net

Commented:
You are missing:
contextMenu1.Show(Cursor.Position);

Hope that helps.
You add code:
ContextMenuStrip contextMenu1 = new ContextMenuStrip();
                        contextMenu1.Items.Add(mi_2);
                        contextMenu1.Items.Add(mi_3);
                        contextMenu1.Items.Add(mi_4);
Point cPt = new Point(e.X, e.Y);
            PointToScreen(cPt);
            contextMenu1.Show(cPt);

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial