how to show contextmenustrip when a button is clicked in the right position

leora picture leora · Oct 11, 2009 · Viewed 48.7k times · Source

I want to click on a button and have it show a ContextMenuStrip right below the button. It keeps showing up in the left hand side of the screen when i try PointToScreen and top and left coordinates.

Any suggestions?

Answer

A J Qarshi picture A J Qarshi · Nov 28, 2011

I know this is an old question but I think it may help other people. Following code will display the context menu just below the button being clicked and the button will look like a dropdown button.

private void Button1_Click(object sender, EventArgs e)
{
    Button btnSender = (Button)sender;
    Point ptLowerLeft = new Point(0, btnSender.Height);
    ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);           
    ctMenuStrip.Show(ptLowerLeft);
}