views:

228

answers:

1

I have a context menu attached to a panel, that should mirror commands available in a toolbar menu.

Currently in my MouseUp event, I set the enabled state of the MenuItems, and add them to the context menu:

    ctxMnuLinks.Items.Clear()
    ctxMnuLinks.Items.Add(mnuLinksOpen)
    ctxMnuLinks.Items.Add(New ToolStripSeparator)
    ctxMnuLinks.Items.Add(mnuLinksAdd)
    ctxMnuLinks.Items.Add(mnuLinksEdit)
    ctxMnuLinks.Items.Add(New ToolStripSeparator)
    ...

..but this removes the items from the toolbar menu! So obviously I can't use the same object. I would like to avoid duplicating the menu, which would leave me 2 sets of menu items to maintain.

What is the proper way to achieve this? I'm looking for a 'best practice' answer.

+3  A: 

I don't think you can have the same object in both the toolstrip and context menu, but they can both call the same function in their OnClick event.

Scott Dorman