Reputation:
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
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
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