user3911053
user3911053

Reputation:

Rich Text Box Select First Character

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.

Upvotes: 1

Views: 1866

Answers (2)

Dylan Corriveau
Dylan Corriveau

Reputation: 2557

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;

Upvotes: 1

Benji_9989
Benji_9989

Reputation: 173

Try :

richTextBox.Select(0, 1);

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

richTextBox.HideSelection = false;
richTextBox.Select(0, 1);

Upvotes: 0

Related Questions