Danny Beckett
Danny Beckett

Reputation: 20867

How to add an icon to a context menu

I have a notification icon with a ContextMenu attached (rather than a ContextMenuStrip, in order to keep the Windows look-and-feel), as detailed here.

How can I add an icon to the context menu items?

Upvotes: 2

Views: 2022

Answers (1)

Blachshma
Blachshma

Reputation: 17405

If you have to use a MenuItem, you'll have to draw the menuitem yourself and add an image. For that, set the OwnerDraw property to true and subscribe to the DrawItem event.

Or

You can derive your own MenuItem class:

public class MyMenuItem : MenuItem
{
    public MyMenuItem()
    {
        OwnerDraw = true;

    }
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        base.OnDrawItem(e);

        // Add paint logic here
    }
}

For specific links on how to draw on the MenuItem see here and here

Upvotes: 1

Related Questions