How to prevent selection of text in a text control (e.g. textbox or richtextbox

Hi all!
I have a richtextbox control which I want to make available to users.
They can read its contents but I don't want them to be able to select any text or copy them

What I have done
1. I set the property of the control to read only
2. I wrote this

 if(rtfCase.SelectedText.Length > 0)rtfCase.SelectedText = "";

in the MouseUp, KeyUp and SelectionChanged events of the RTF control, but no luck.
Can someone please help me out.

Thank you
innovator2Asked:
Who is Participating?
 
rubixxcubeConnect With a Mentor Commented:
I would simply set the Enabled property of the control to false.
If you don't want to do that then you could use the selectionChanged event as follows:
private void rtf_SelectionChanged(object sender, System.EventArgs e)
            {
                  if(rtf.SelectedText.Length>0)
                  {
                        rtf.Select(0,0);
                  }
            }
0
 
innovator2Author Commented:
Thanks. It works fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.