Insert HTML at the caret

    HTML insertion lets users add prepared content, such as a signature, a standard clause or a formatted block, at the current caret. Call Content.InsertHtml with the fragment to insert. Its keepSelected argument controls whether the new content stays selected.

    The command can sit anywhere in your own UI - an ordinary button on your form, a menu item, or a custom button you add to the editor's built-in toolbar. Toolbar buttons are added in code rather than through the Visual Studio designer: Toolbar1 and its buttons are exposed as read-only accessors and are deliberately not serialized into InitializeComponent, so that the control owns its own toolbar layout. Add a custom button to the built-in toolbar shows that in full.

    The examples below assume the editor instance is named winFormHtmlEditor1 and the button is named btnInsert.

    A custom button labelled Insert signature added in code to the end of the SpiceLogic WinForms HTML Editor's built-in toolbar, sitting alongside the factory buttons in a running application.
    A custom button labelled Insert signature added in code to the end of the SpiceLogic WinForms HTML Editor's built-in toolbar, sitting alongside the factory buttons in a running application.

    Wire that button's Click event to a handler - btnInsert_Click here - the same way you would wire any other button in your application. Your handler runs on the click, so anything it does to the editor happens against the live document:

    The custom toolbar button's Click handler after a real click in the SpiceLogic WinForms HTML Editor: the host application's activity line reports the handler ran and the signature it inserted appears at the caret.
    The custom toolbar button's Click handler after a real click in the SpiceLogic WinForms HTML Editor: the host application's activity line reports the handler ran and the signature it inserted appears at the caret.

    Now, within that click event handler, you can write code like this:

    private void btnInsert_Click(object sender, EventArgs e)
    {
        winFormHtmlEditor1.Content.InsertHtml("<span style='color:red;'>Sep 30</span> <span style='color:blue;'>renewal</span>", keepSelected: true);
    }
    Private Sub btnInsert_Click(sender As Object, e As EventArgs)
        winFormHtmlEditor1.Content.InsertHtml("<span style='color:red;'>Sep 30</span> <span style='color:blue;'>renewal</span>", keepSelected:=True)
    End Sub

    Now, you can run the application. Say your document contains a client notice, and your caret is positioned immediately before the word 'deadline'.

    The SpiceLogic WinForms HTML Editor at runtime inside a client notice application, with the text caret positioned mid-sentence immediately before the word deadline, ready for the custom button to insert HTML at that exact spot.
    The SpiceLogic WinForms HTML Editor at runtime inside a client notice application, with the text caret positioned mid-sentence immediately before the word deadline, ready for the custom button to insert HTML at that exact spot.

    Clicking the button runs that handler, and the snippet lands at the caret:

    After InsertHtml is called with keepSelected set to true, the SpiceLogic WinForms HTML Editor shows the newly inserted Sep 30 renewal text still highlighted as a live selection.
    After InsertHtml is called with keepSelected set to true, the SpiceLogic WinForms HTML Editor shows the newly inserted Sep 30 renewal text still highlighted as a live selection.

    You see that the inserted snippet is highlighted. That is because we passed the second argument of the method "keepSelected = true". If you pass that argument as false, then the inserted snippet will not be highlighted upon insertion. Anyway, once you deselect that part, you will see the snippet as follows:

    After InsertHtml is called with keepSelected set to false, the SpiceLogic WinForms HTML Editor shows the same Sep 30 renewal text inserted at the caret with no selection highlight left behind.
    After InsertHtml is called with keepSelected set to false, the SpiceLogic WinForms HTML Editor shows the same Sep 30 renewal text inserted at the caret with no selection highlight left behind.

    Ask your AI to do this

    Connect the SpiceLogic MCP server, then give your coding assistant this prompt.

    I use the SpiceLogic WinForms HTML Editor. Help me insert an HTML fragment at the current caret without replacing the document. Confirm the exact API names, types and defaults with the SpiceLogic MCP documentation, then show the changes for my project.

    Last updated on Oct 9, 2026

    Put this into practice.

    Clone the C# and VB.NET sample projects from GitHub. Start with Quickstart, then explore the feature samples.

    Prefer a guided look? Book a free live demo with our engineers - live on Zoom or Teams, never a chatbot.