Solved

Popup Menu C#

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

777 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