Solved

Popup Menu C#

Posted on 2011-09-06
3
233 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:AndyC1000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36487447
Is that the complete code?

I don't see anything about showing or positioning the context menu for instance.
0
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 36487450
You are missing:
contextMenu1.Show(Cursor.Position);

Hope that helps.
0
 
LVL 15

Accepted Solution

by:
Minh Võ Công earned 250 total points
ID: 36487456
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);
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question