Context Menu Example
Information for Developers
Following is an example of how to add and properly remove a context menu item for a given instance of IDocument. See IDocument Interface.
Copy
public void AddContextMenuItem(IDocument doc)
{
if (doc != null)
{
List<System.Windows.Forms.ToolStripItem> cms = doc.GetUserPendingContextMenuItems();
cms.Add(new System.Windows.Forms.ToolStripMenuItem("Editor Plugin Item"));
}
}
public void RemoveContextMenuItem(IDocument doc)
{
if (doc != null)
{
List<System.Windows.Forms.ToolStripItem> cms = mCurrentDocument.GetUserPendingContextMenuItems();
cms.Clear();
}
}
Note If you have multiple documents with custom context menu items, you need to manually clear their context “toolstripitem” lists.