This solution works in c#:
private void HighlightWord(Scintilla scintilla, string text)
{
if (string.IsNullOrEmpty(text))
return;
// Indicators 0-7 could be in use by a lexer
// so we'll use indicator 8 to highlight words.
const int NUM = 8;
// Remove all uses of our indicator
scintilla.IndicatorCurrent = NUM;
scintilla.IndicatorClearRange(0, scintilla.TextLength);
// Update indicator appearance
scintilla.Indicators[NUM].Style = IndicatorStyle.StraightBox;
scintilla.Indicators[NUM].Under = true;
scintilla.Indicators[NUM].ForeColor = Color.Green;
scintilla.Indicators[NUM].OutlineAlpha = 50;
scintilla.Indicators[NUM].Alpha = 30;
// Search the document
scintilla.TargetStart = 0;
scintilla.TargetEnd = scintilla.TextLength;
scintilla.SearchFlags = SearchFlags.None;
while (scintilla.SearchInTarget(text) != -1)
{
// Mark the search results with the current indicator
scintilla.IndicatorFillRange(scintilla.TargetStart, scintilla.TargetEnd - scintilla.TargetStart);
// Search the remainder of the document
scintilla.TargetStart = scintilla.TargetEnd;
scintilla.TargetEnd = scintilla.TextLength;
}
}
Call is simple, in this example the words beginning with @ will be highlighted:
Regex regex = new Regex(@"@\w+");
string[] operands = regex.Split(txtScriptText.Text);
Match match = regex.Match(txtScriptText.Text);
if (match.Value.Length > 0)
HighlightWord(txtScriptText, match.Value);