Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Intercepting Inserted Text

jacobslusser edited this page May 31, 2015 · 2 revisions

There are numerous events to inform you of when text has changed. In addition to the TextChanged event provided by almost all Windows Forms controls, Scintilla also provides events for Insert, Delete, BeforeInsert, and BeforeDelete. By using these events you can trigger other changes in your application.

These events are all read-only, however. Changes made by a user to the text can be observed, but not modified--with one exception. The InsertCheck event occurs before text is inserted (and earlier than the BeforeInsert event) and is provided for the express purpose of giving you an option to modify the text being inserted. This can be used to simply cancel/prevent unwanted user input. Or in more advanced situations, it could be used to replace user input.

The following code snippet illustrates how you might handle the InsertCheck event to transform user input to HTML encode input:

private void scintilla_InsertCheck(object sender, InsertCheckEventArgs e)
{
    e.Text = WebUtility.HtmlEncode(e.Text);
}