Я пытался найти плагин или какой-то ярлык, который существует в eclipse для этой функции. Удивительно ... Итак, я пытаюсь выделить текст, содержащийся в моем RichTextBox. В настоящее время у меня есть следующее ...
Я пытаюсь использовать RichTextBox, и мое первое чувство: «Что с этим сложно использовать!» ... Удивительно ...
Итак, я пытаюсь выделить текст, содержащийся в моем RichTextBox.
В настоящее время у меня есть следующий код:
TextRange range = new TextRange(MyTextInput.Document.ContentStart, MyTextInput.Document.ContentEnd);
range.Text = @"TOP a multiline text or file END";
Regex reg = new Regex("(top|file|end)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
foreach (Match match in reg.Matches(range.Text))
{
TextPointer start = range.Start.GetPositionAtOffset(match.Index, LogicalDirection.Forward);
TextPointer end = range.Start.GetPositionAtOffset(match.Index + match.Length, LogicalDirection.Backward);
// text contains the exact match I want
string text = range.Text.Substring(match.Index, match.Length);
// here the highlighted text isn't the text I searched...
TextRange textrange = new TextRange(start, end);
textrange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(Colors.Blue));
textrange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
}
TOP
выделен правильно, но не файл
или end
, но выделите меня или
.
Есть предложения?