Solved

Popup Menu C#

Posted on 2011-09-06
3
227 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
A simple description of email encryption using a secure portal service. This is one of the choices offered by The Email Laundry for email encryption. The other choices are pdf encryption which creates an encrypted pdf of your email and any attachmen…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now