开发者

How to change already entered lines in a RichTextBox?

开发者 https://www.devze.com 2023-01-06 01:24 出处:网络
How does one change already appended or entered lines on the RichTextBox control? I want 开发者_如何学Cto programmaticlyinsert a Timestamp in front of each line of input. TextBox1.Lines[] does not a

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

精彩评论

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

关注公众号