views:

18

answers:

1

How does one change already appended or entered lines on the RichTextBox control?

I want to 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.

One thinks this is possible.

Thanks

DJK

+1  A: 

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;
Hans Passant