In general, I have a menu, and when I click on one of the ToolStripMenuItem , I want the context menu to appear with my buttons. How can I do that?

    2 answers 2

    If you need to hang on ToolStripMenuItem exactly ContextMenuStrip , then on ToolStripMenuItem hang up a MouseDown or Click event, and inside the method, invoke the forced display of the context menu:

     private void toolStripButton1_MouseDown(object sender, MouseEventArgs e) { contextMenuStrip1.Show(Cursor.Position); } 

    Another option: Insert into ToolStrip ToolStripSplitButton , there is an opportunity to make a drop-down menu. In order for this menu to open not only by clicking on the arrow, call the event handler for the ButtonClick event, and in the method, call the opening of the drop-down menu:

     private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e) { toolStripSplitButton1.ShowDropDown(); } 

      Alternatively, if you have a fixed-size window, then

       private void МойToolStripMenuItem_Click(object sender, EventArgs e) { contextMenuStrip1.Show(menuStrip1 , x, y); } 

      COntextMenuStrip1 - your context menu.
      x*y is the point at which your context menu appears.
      You can take these values ​​from the mouse pointer.

      • @Andrey Anfilets; To format a code, select it with the mouse and click on the {} button of the editor. - Pavel Azanov