Question

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!

Was it helpful?

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);
        }
    }

OTHER TIPS

You haven't shown any code, but if you're not calling the Show overload that takes a control as a parameter, the new Point(0, 0) that your obviously passing will put the menu in the upper left of the screen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top