Replacing the editor's right-click context menu
The WinForms HTML Editor's default right-click context menu covers general editing commands: cut, copy, paste, table commands, image properties. Your app may need more than that - a CRM note editor that lets a rep link the current selection to a support ticket, or a ticketing app that turns selected text into a task, right from the same right-click gesture users already reach for. Replace the default menu with your own ContextMenuStrip when your document needs commands like these instead of, or alongside, the built-in ones. This page shows how to swap the menu, enable or disable items based on the current selection, and observe right-clicks without touching the built-in menu at all.
Replace the menu via EditorContextMenuStrip
The editor exposes a single property for this: EditorContextMenuStrip, of type System.Windows.Forms.ContextMenuStrip. Assign your own strip and the editor uses it whenever the user right-clicks inside the document surface.
private void NoteEditorForm_Load(object sender, EventArgs e) {
var menu = new ContextMenuStrip();
var linkToTicket = new ToolStripMenuItem("Link to Ticket...");
linkToTicket.Click += (s, args) =>
{
var ticketId = TicketPicker.Show(this);
if (ticketId != null)
{
string anchor = $"<a href=\"crm://ticket/{ticketId}\">#{ticketId}</a>";
htmlEditor1.Content.InsertHtml(anchor, keepSelected: false);
}
};
var convertToTask = new ToolStripMenuItem("Convert Selection to Task");
convertToTask.Click += (s, args) =>
{
string selected = htmlEditor1.Selection.GetSelectedHtml();
if (!string.IsNullOrWhiteSpace(selected))
TaskService.CreateFromHtml(currentAccount.Id, selected);
};
menu.Items.Add(linkToTicket);
menu.Items.Add(new ToolStripSeparator());
menu.Items.Add(convertToTask);
// Hand the strip to the editor. From now on, right-clicking inside the
// note shows this menu instead of the built-in one.
htmlEditor1.EditorContextMenuStrip = menu;
}Private Sub NoteEditorForm_Load(sender As Object, e As EventArgs)
Dim menu = New ContextMenuStrip()
Dim linkToTicket = New ToolStripMenuItem("Link to Ticket...")
AddHandler linkToTicket.Click, Sub(s, args)
Dim ticketId = TicketPicker.Show(Me)
If ticketId IsNot Nothing Then
Dim anchor As String = $"<a href=""crm://ticket/{ticketId}"">#{ticketId}</a>"
htmlEditor1.Content.InsertHtml(anchor, False)
End If
End Sub
Dim convertToTask = New ToolStripMenuItem("Convert Selection to Task")
AddHandler convertToTask.Click, Sub(s, args)
Dim selected As String = htmlEditor1.Selection.GetSelectedHtml()
If Not String.IsNullOrWhiteSpace(selected) Then TaskService.CreateFromHtml(currentAccount.Id, selected)
End Sub
menu.Items.Add(linkToTicket)
menu.Items.Add(New ToolStripSeparator())
menu.Items.Add(convertToTask)
' Hand the strip to the editor. From now on, right-clicking inside the
' note shows this menu instead of the built-in one.
htmlEditor1.EditorContextMenuStrip = menu
End SubDisable items based on current state
To disable an item conditionally, for example greying out a command when there is no selection, handle the Opening event on the EditorContextMenuStrip (a normal Windows Forms ContextMenuStrip):
menu.Opening += (s, args) => {
string selected = htmlEditor1.Selection.GetSelectedHtml();
convertToTask.Enabled = !string.IsNullOrWhiteSpace(selected); };AddHandler menu.Opening, Sub(s, args)
Dim selected As String = htmlEditor1.Selection.GetSelectedHtml()
convertToTask.Enabled = Not String.IsNullOrWhiteSpace(selected)
End SubThe ContextMenuShowing event: a notification hook
To observe right-clicks without replacing the menu, for example for usage analytics, handle the ContextMenuShowing event. It fires on every right-click inside the document surface, and its event args give you the cursor position relative to the editor:
htmlEditor1.ContextMenuShowing += (sender, e) => {
// e.OffsetMousePosition is the cursor location relative to the editor surface.
AnalyticsClient.Track(
"NoteEditorRightClick",
new { x = e.OffsetMousePosition.X, y = e.OffsetMousePosition.Y }); };AddHandler htmlEditor1.ContextMenuShowing, Sub(sender, e)
' e.OffsetMousePosition is the cursor location relative to the editor surface.
AnalyticsClient.Track("NoteEditorRightClick", New With {Key .x = e.OffsetMousePosition.X, Key .y = e.OffsetMousePosition.Y})
End SubNote: ContextMenuShowingEventArgs only carries OffsetMousePosition. There is no Cancel property and no MenuItems collection, so you cannot suppress or modify the built-in menu from this event. To show a different menu, use EditorContextMenuStrip instead; this event is for observation only.
Because the strip is built once in code, you can extend it later, for example adding another ToolStripMenuItem for a new command, without changing how it is wired to the editor.


Ask your AI to do this
Let your assistant do this for you. With the SpiceLogic MCP server connected, paste this into Claude Code, Cursor, or VS Code Copilot in agent mode.
Using the SpiceLogic WinForms HTML Editor already referenced in my project, replace the editor's default right-click context menu with my own ContextMenuStrip by assigning it to the EditorContextMenuStrip property, adding a custom item labeled "Link to support ticket" that only enables when text is currently selected. Keep the built-in table and image commands available the way they work today, and wire the new item so it reads the current selection when clicked. Look up the real API with the SpiceLogic MCP tools before writing any code.