Changing a ContextMenuStrip Location

I'm using a ContextMenuStrip on a TreeView control and distinguishing from when it is opened by the mouse, versus by the keyboard.

When it is opened by the keyboard, it is always displayed in the center of the TreeView. I want to position it over the current selected node.

Anyone know how to do this You would think perhaps setting the anonymous location property appropriately would work, but alas, not so.

Last resort, I'm asking here.

Thank you,

Sean Allison



Answer this question

Changing a ContextMenuStrip Location

  • Elmer_927

    I'm in the middle of the OnOpening event already and thought that would start another. It didn't, so that works for me like a shot.

    Many thanks.


  • paulkossler

    Hi,
    try it like this:
    contextMenuStrip1.Show(treeView1, new Point(treeView1.SelectedNode.Bounds.X, treeView1.SelectedNode.Bounds.Y));

    Don't know if it's the only or easiest way but I think it works. The TreeNodes also have a property to assign a ContextMenuStrip but last time I tried the menu appeared in the top left corner of my desktop.


  • Changing a ContextMenuStrip Location