Other Useful Events

    This page documents the events on WinFormHtmlEditor that are useful but less frequently subscribed than the ones on the main Useful Events page (HtmlChanged, Pasting, SelectionChanged, EditorModeChanged, ContextMenuShowing).

    Namespace: SpiceLogic.HtmlEditor.WinForms
    Assembly: SpiceLogic.HtmlEditor.WinForms.dll

    HtmlElementClicked

    Occurs when an HTML element of a registered type is clicked inside the editor surface. To get this event for a given element type, list that type in Options.FireHtmlElementClickEventFor before the editor is initialized; the editor then attaches the necessary MSHTML hooks for you.

    Syntax
    public event EventHandler<HtmlElementClickedEventArgs> HtmlElementClicked;
    Public Event HtmlElementClicked As EventHandler(Of HtmlElementClickedEventArgs)
    Event Data (HtmlElementClickedEventArgs)
    MemberTypeDescription
    ElementTypeHtmlElementTypesThe classified element type: Hyperlink, Image, Table, Paragraph, Span, Div, Input, or Other.
    ClickedElementSystem.Windows.Forms.HtmlElementThe clicked element. Use GetAttribute, InnerText, etc. to inspect it.
    EventDataSystem.Windows.Forms.HtmlElementEventArgsThe raw event args from the underlying MSHTML click. Set EventData.ReturnValue = false to cancel the editor's default handling.
    Remarks

    The event does not fire for element types you have not enabled. If Options.FireHtmlElementClickEventFor is empty, no clicks raise this event regardless of the handler.

    Example
    using SpiceLogic.HtmlEditor.Abstractions;
    
    htmlEditor1.Options.FireHtmlElementClickEventFor = HtmlElementTypes.Hyperlink;
    htmlEditor1.HtmlElementClicked += (s, e) =>
    {
        if (e.ElementType == HtmlElementTypes.Hyperlink)
        {
            string href = e.ClickedElement.GetAttribute("href");
            MessageBox.Show("Hyperlink clicked: " + href);
        }
    };
    Imports SpiceLogic.HtmlEditor.Abstractions
    
    htmlEditor1.Options.FireHtmlElementClickEventFor = HtmlElementTypes.Hyperlink
    htmlEditor1.HtmlElementClicked += Sub(s, e)
                                          If e.ElementType Is HtmlElementTypes.Hyperlink Then
                                              Dim href As String = e.ClickedElement.GetAttribute("href")
                                              MessageBox.Show("Hyperlink clicked: " & href)
                                          End If

    HtmlElementMouseDown

    Occurs when a mouse-button press is detected on an HTML element of a registered type. Same activation model as HtmlElementClicked -- list the element types in Options.FireHtmlElementMouseDownEventFor.

    Syntax
    public event EventHandler<HtmlElementClickedEventArgs> HtmlElementMouseDown;
    Public Event HtmlElementMouseDown As EventHandler(Of HtmlElementClickedEventArgs)
    Event Data

    Same HtmlElementClickedEventArgs shape as HtmlElementClicked.

    Remarks

    Subscribe to this event when you need to react before the click's default action -- for example, to capture a custom drag-start point on an image.

    Example
    using SpiceLogic.HtmlEditor.Abstractions;
    
    htmlEditor1.Options.FireHtmlElementMouseDownEventFor = HtmlElementTypes.Image;
    htmlEditor1.HtmlElementMouseDown += (s, e) =>
    {
        if (e.ElementType == HtmlElementTypes.Image)
            _dragSrc = e.ClickedElement.GetAttribute("src");
    };
    Imports SpiceLogic.HtmlEditor.Abstractions
    
    htmlEditor1.Options.FireHtmlElementMouseDownEventFor = HtmlElementTypes.Image
    htmlEditor1.HtmlElementMouseDown += Sub(s, e)
                                            If e.ElementType Is HtmlElementTypes.Image Then _dragSrc = e.ClickedElement.GetAttribute("src")

    FileOpened

    Raised after the editor successfully loads a file via Content.LoadBodyHtmlFromFile, Content.LoadDocumentHtmlFromFile, or Content.OpenFile. The event args carry the full path of the file that was loaded.

    Syntax
    public event EventHandler<FileEventArgs> FileOpened;
    Public Event FileOpened As EventHandler(Of FileEventArgs)
    Event Data (FileEventArgs)
    MemberTypeDescription
    FilePathstringThe full path of the file that was loaded. Never null; will be string.Empty when the editor could not resolve a path.
    Example
    htmlEditor1.FileOpened += (s, e) =>
    {
        Text = "Editor - " + Path.GetFileName(e.FilePath);
        AddToRecentFiles(e.FilePath);
    };

    FileSaved

    Raised after the editor successfully writes a file via Content.SaveBodyHtmlToFile, Content.SaveDocumentHtmlToFile, or Content.SaveEditorContentAsXml.

    Syntax
    public event EventHandler<FileEventArgs> FileSaved;
    Public Event FileSaved As EventHandler(Of FileEventArgs)
    Event Data (FileEventArgs)
    MemberTypeDescription
    FilePathstringThe full path of the file that was written.
    Example
    htmlEditor1.FileSaved += (s, e) =>
    {
        isDirty = false;
        statusLabel.Text = "Saved to " + e.FilePath;
    };
    htmlEditor1.FileSaved += Sub(s, e)
                                 isDirty = False
                                 statusLabel.Text = "Saved to " & e.FilePath.ToString()

    ErrorOccurred

    Raised when an internal error occurs that the editor would otherwise have to swallow silently -- typically a file-IO failure, a clipboard failure, or an MSHTML interop exception. Subscribe to log the error or display a user-facing message.

    Syntax
    public event EventHandler<ErrorEventArgs> ErrorOccurred;
    Public Event ErrorOccurred As EventHandler(Of ErrorEventArgs)
    Event Data (ErrorEventArgs)
    MemberTypeDescription
    MessagestringA human-readable description of the error.
    ExceptionSystem.Exception?The underlying exception when one is available; null for errors that did not originate from an exception.
    Remarks

    The editor never raises fatal exceptions through this event -- those still propagate to the host. Use this event purely for observability.

    Example
    htmlEditor1.ErrorOccurred += (s, e) =>
    {
        Log.Error(e.Exception, e.Message);
        statusLabel.Text = "Error: " + e.Message;
    };

    StatusChanged

    Raised when the editor wants to publish a status update -- for example, "Spell-checking started", "Image loaded", "Document modified". Subscribe to surface these messages in your application's status bar.

    Syntax
    public event EventHandler<StatusChangedEventArgs> StatusChanged;
    Public Event StatusChanged As EventHandler(Of StatusChangedEventArgs)
    Event Data (StatusChangedEventArgs)
    MemberTypeDescription
    StatusMessagestringThe status message text.
    Remarks

    The editor marshals this event to the UI thread via SynchronizationContext.Post, so it is safe to update WinForms controls directly inside the handler regardless of which thread the message originated on.

    Example
    htmlEditor1.StatusChanged += (s, e) =>
    {
        statusLabel.Text = e.StatusMessage;
    };

    SpellCheckCompleted

    Occurs when a spell-check pass finishes, either because every misspelling has been resolved or because the user dismissed the spell-check dialog.

    Syntax
    public event EventHandler<SpellCheckCompletedEventArgs> SpellCheckCompleted;
    Public Event SpellCheckCompleted As EventHandler(Of SpellCheckCompletedEventArgs)
    Event Data (SpellCheckCompletedEventArgs)
    MemberTypeDescription
    Canceledbooltrue when the user closed the dialog before finishing; false when the pass ran to completion.
    Remarks

    This event fires once per top-level spell-check pass triggered by the toolbar button or by SpellCheckerService.SpellCheck. The inline (background) checker that highlights misspellings as the user types does not raise this event.

    Example
    htmlEditor1.SpellCheckCompleted += (s, e) =>
    {
        statusLabel.Text = e.Canceled
            ? "Spell check canceled"
            : "Spell check complete";
    };

    See also

    For the five most-used events (HtmlChanged, Pasting, SelectionChanged, EditorModeChanged, ContextMenuShowing) see the Useful Events page in this section.

    Last updated on May 14, 2026