Windows Forms RichTextBox cursor position

前端 未结 3 1394
忘了有多久
忘了有多久 2021-01-17 11:27

I have a C# Windows Forms program that has a RichTextBox control. Whenever the text inside the box is changed (other than typing that change), the cursor goes back to the be

3条回答
  •  感情败类
    2021-01-17 12:18

    Be careful, if someone refreshes or changes totally the RichTextBox content, the focus method must be invoqued previously in order to move the caret:

    richTextBox1.Focus();
    int i = richTextBox1.SelectionStart;
    richTextBox1.Text = strPreviousBuffer;
    richTextBox1.SelectionStart = i;
    

提交回复
热议问题