开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜