Search code examples
c#winformsvisual-studio-2008contextmenustrip

ContextMenuStrip renders at top left Windows


When i render contextmenustrip, it gets render at the top left of my PC Screen. I have a listview, which contains 5-6 items and on right click of each item, the context Menu strip gets displayed.Also i need to change the color of context menu strip including backgrounds and text as well.

Thanks in advance!


Solution

  • By far the simplest way is to just set the ListView.ContextMenuStrip property to your CMS, everything is automatic then. You can do so in the designer.

    If you need a custom handler for some reason, to check if the right item was clicked for example, then you can call the Show() method property with code like this:

        private void listView1_MouseClick(object sender, MouseEventArgs e) {
            if (allowContextMenu(listView1.SelectedItems) {
                contextMenuStrip1.Show(listView1, e.Location);
            }
        }