Disable delete button on RichTextBox WF

前端 未结 5 826
无人及你
无人及你 2021-01-14 20:36

I am trying to disable people from deleting a textbox in a richtextbox. The project is using windows form.

Here is the code I have:

    private void         


        
5条回答
  •  梦谈多话
    2021-01-14 20:42

    My solution:

    void richTextBox1_TextChanged(object sender, EventArgs e) {
      richTextBox1.SelectAll();
      richTextBox1.SelectionProtected = true;
      richTextBox1.Select(richTextBox1.Text.Length, 0);
    }
    

    Side note: yes, this will flicker. Proof of concept only. To avoid the flicker, see How to append text to RichTextBox without scrolling and losing selection?

提交回复
热议问题