I have a ContextMenuStrip (ctMenuMassEdit) that I want to display when I left-click (btnMassEdit). I want the ContextMenuStrip to appear above the button, i.e. the position (0, -ContextMenuStrip.Height) relative to the button:
private void btnMassEdit_Click(object sender, EventArgs e) { ctMenuMassEdit.Show(btnMassEdit, new Point(0, -ctMenuMassEdit.Height)); }
However, the Height property is 0 the first time the button is clicked (I assume that ContextMenuStrip is not created before it is shown for the first time), and the result is that ContextMenuStrip appears on top of the button. The second time I press the button, however it is displayed in the correct position, so the main logic of my logic is at least correct.
I tried to add the following before showing ContextMenuStrip, but this did not work as I would like:
if (!ctMenuMassEdit.Created) { ctMenuMassEdit.CreateControl(); }
So, is there a way to create a ContextMenuStrip before showing it for the first time, so that I have the correct Height property? I could, of course, crack it, hide it and show it again, but that doesn't seem really neat ...
source share