0

I'm working in wpf and visual basic. When I select text in RichTextBox i use TextRange:

dim selection1 as New TextRange(Richtextbox.selection.start,Richtextbox.selection.end)

Later:

selection1.ApplyPropertyValue(ForegroundProperty, brushes.Red)

When I am marking text many times the color changes also in the previous selections. I want change color only last selection. How to do this?

Taterhead
  • 5,763
  • 4
  • 31
  • 40
Inum
  • 53
  • 1
  • 7

1 Answers1

0

Why don't you cache the previous selection and previous color?

RichTextBox.BeginChange();
selection?.ApplyPropertyValue(ForegroundProperty, lastColor);
selection = RichTextBox.Selection;
selection.ApplyPropretyValue(ForegroundProperty, newColor);
RichTextBox.EndChange();
imokaythanks
  • 178
  • 3
  • 9