1

Is there a way in C# to select the first character of the text in a paragraph in a Rich Text Box? I want to do something like this:

richTextBox.Selection.Select(0, 1);

0 being the start position and 1 being the selection end position.

MX D
  • 2,453
  • 4
  • 35
  • 47
  • 1
    check this one out: http://stackoverflow.com/questions/1454440/select-range-of-text-in-wpf-richtextbox-flowdocument-programmatically – İsmet Alkan Oct 14 '14 at 13:23
  • http://stackoverflow.com/questions/957441/richtextbox-wpf-does-not-have-string-property-text – blfuentes Oct 14 '14 at 13:33

2 Answers2

1

You could use the TextRange object to do that. This should return the first character in your richtextbox

TextRange justTheFirst = new TextRange(richTextBox.Document.ContentStart,
                                       richTextBox.Document.ContentStart.GetPositionAtOffset(1));
string text = justTheFirst.Text;
Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
0

Try :

richTextBox.Select(0, 1);

Maybe you'll need to set the hideSelection to false before;

richTextBox.HideSelection = false;
richTextBox.Select(0, 1);
Benji_9989
  • 173
  • 8