How to change already entered lines in a RichTextBox?
How does one change already appended or entered lines on the RichTextBox control?
I want 开发者_如何学Cto programmaticly insert a Timestamp in front of each line of input. TextBox1.Lines[] does not allow changes. I attempted to set my own array to Lines[] but didn't seems to work.
Use the RichTextBox.GetFirstCharIndexFromLine() method to find out where to insert the text. For example:
int prev = richTextBox1.SelectionStart;
int cnt = richTextBox1.Lines.Length;
for (int line = 0; line < cnt; line++) {
richTextBox1.SelectionStart = richTextBox1.GetFirstCharIndexFromLine(line);
richTextBox1.SelectionLength = 0;
richTextBox1.SelectedText = DateTime.Now.ToString() + ": ";
}
richTextBox1.SelectionStart = prev;
精彩评论