How can I show a contextMenuStrip when a user right click a mainMenuStrip item?

Hello,

Can you please tell me how can I show a contextMenuStrip when a user right click a mainMenuStrip item

Exactly like Internet Explorer Favorite menu and Firefox Bookmarks menu.

Thanks in advance.


Answer this question

How can I show a contextMenuStrip when a user right click a mainMenuStrip item?

  • SnakeSV

    Sorry for the wait. I have been on a business meeting trip.
    As far as what you are doing....do this:



    pass in the control or button control that you want the context menu to associate to, and a point.

    So:

    // Point where the mouse is clicked.
    Point p = new Point(e.X, e.Y);

    this.myDesignTimeCreatedContextMenuStrip.Show(the toolbar control object, p);

  • belisa

    You are going to have to get do a mouse_up event on the toolbar button itself.

    this.ExampleBtn.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ExampleBtn_MouseUp);

    Then what you are going to do is check what button was clicked.

    private void ExampleBtn_MouseUp(object sender, MouseEventArgs e)
    {
    if (e.Button == MouseButtons.Right)
    {
    create context menu...bla bla bla.
    }
    }

    Hope this points you in the right direction.




  • JayR

    Thanks a lot. It worked but there's a little bug.

    I used your code and I changeed:

    create context menu...bla bla bla.

    To:

    myDesignTimeCreatedContextMenuStrip.Show(new Point(Cursor.Position.X, Cursor.Position.Y));

    The problem is when I right click on a menu item the main menu (Favorites) is being closed as soon as the context menu is shown.

    How can I fix that

  • How can I show a contextMenuStrip when a user right click a mainMenuStrip item?