Lock part of text in RichTextBox

B

BVM

Hi, friends:

Do you know how to lock some of text in RichTextBox? Because I don't want user to change what other people have already wriiten in the RichTextBox.

Thanks,

Dennis Huang
 
M

Morten Wennevik

Hi Dennis,

Use the SelectionProtected property to mark text protected.
This sample will select all text in the richTextBox and mark it as protected.
The user can add more text, but cannot change the protected text.

richTextBox1.Text = "Hello World, this is a protected sentence.\n";
richTextBox1.SelectAll();
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionProtected = true;
richTextBox1.SelectionLength = 0;
richTextBox1.SelectionStart = richTextBox1.TextLength+1;

It also changes the protected text to red.
Note that you cannot change the text programmatically either until you unprotect the text.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top