tr0yspradling
tr0yspradling

Reputation: 604

Insert string in RichTextBox at cursor position

I'm trying to insert a string at the cursor's position.. I'm writing a syntax highlighter control and I'm wanting to make a function so the user can comment out a line of code. "// blah" all this would do is insert the specified comment identifier..

Upvotes: 2

Views: 2739

Answers (2)

Hans Passant
Hans Passant

Reputation: 942348

richTextBox1.SelectionLength = 0;
richTextBox1.SelectedText = "//";

Upvotes: 2

Jalal Said
Jalal Said

Reputation: 16162

richTextBox.GetCharIndexFromPosition(Point point)

Will give you the character index.

Another method that could help you:

richTextBox.GetFirstCharIndexFromLine(int lineNumber);
richTextBox.GetFirstCharIndexOfCurrentLine();
richTextBox.GetLineFromCharIndex(int index);

Upvotes: 0

Related Questions