Disable delete button on RichTextBox WF

前端 未结 5 791
无人及你
无人及你 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 21:07

    Instead Of KeyPress event use KeyDown In RichText Box.

    try this to prevent from deleting text in RichText Box

    private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyValue == 46)
                    e.Handled = true;
            }
    

    If you want to disallow both delete and backspace You Can Change KeyDown Event as follows

    private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyValue == 8 || e.KeyValue == 46)
                    e.Handled = true;
            }
    

提交回复
热议问题