'Why ContextMenuStrip is not opening at first time click from a button in C#?

I am currently developing a Matrix(layout) Popup Menu using a Form. Inside the popup menu, there's a Button. The button should open a ContextMenuStrip when left clicked, but not right clicked. With that, I didn't assign the ContextMenuStrip to the ContextMenuStrip properties of the button, in the Design panel of the Microsoft Visual Studio. Just for your information, the ContextMenuStrip's location is directly under the Button.


Below are the examples to help you to visualize.

  • This is how the Matrix Popup Menu looks like:
    the popup menu

  • This is how the Button should look like with the ContextMenuStripopened: the cs

As the title suggests, I can't open the ContextMenuStrip at the first click of the button. It however works on the next clicks. I've tried solution(s) from these links, but to no avail:

  1. Solution 1.
  2. Solution 2.
  3. Solution 3.


Below are the codes involved(all inside of MatrixPopupMenu.cs):

//global variable
private Point contextStripLocation;

//zoomFactorContextStrip -> name of the ContextMenuStrip object

//the button's click event handler
private void button15_Click(object sender, EventArgs e)
{
    if((e as MouseEventArgs).Button == MouseButtons.Left)
    {
        zoomFactorContextStrip.Show(button15, contextStripLocation);
    }
}

//matrix popup menu's load event handler
private void MatrixPopupMenu_Load(object sender, EventArgs e)
{
    contextStripLocation = new Point(0, this.button15.Height);
}


May I know what can I do to fix this, please?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source