Search and Change Text Style Example

Information for Developers

Following is a basic example where IEditorContext is used to search for a input string and change the style of it throughout the document. See IEditorContext Interface.

In this example, assume your class instance of IEditorContext is named “mEditorContext.”

Copy
private void SearchAndChangeStyle(string searchString)
{
IDocument currentDocument = mEditorContext.GetActiveDocument();
if (currentDocument != null)
{
string text = currentDocument.GetDocumentText();
int occurences = Regex.Matches(text, searchString).Count;
for (int i = 0; i < occurences; i++)
{
currentDocument.Select(searchString);
currentDocument.Selection.ChangeBackColor(Color.Yellow);
currentDocument.Selection.ChangeForeColor(Color.Red);
currentDocument.Selection.ChangeFontFamily("Comic Sans MS");
}
}
}