Solved

Popup Menu C#

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

19 Experts available now in Live!

Get 1:1 Help Now