Help with protected text in RichTextBox

  • Thread starter Thread starter MLM450
  • Start date Start date
M

MLM450

I need to programmatically delete protected text in a RichTextBox. The
problem is that I can't find a way to do it without getting
undesirable results in the undo buffer.

If I unprotect the text and delete, 2 entries go into the undo buffer.
If the user performs a single undo, they get back the text unprotected.

If I copy the entire RTF text, make my changes and copy it back, the
undo buffer is initialized.

Any ideas?
Thanks!
 
// start is the starting position of the protected text.
// end is the final position of the protected text.

// OPTION #1: Results in two "undo" entries.
MyRichTextBox.SelectionStart = start;
MyRichTextBox.SelectionLength = end - start + 1;
MyRichTextBox.SelectionProtected = false;
MyRichTextBox.SelectedRtf = "";

// OPTION #2: Results in "undo" buffer being initialized.
RichTextBox temp = new RichTextBox();
temp.Rtf = MyRichTextBox.Rtf;
temp.SelectionStart = start;
temp.SelectionLength = end - start + 1;
temp.SelectionProtected = false;
temp.SelectedRtf = "";
MyRichTextBox.Rtf = temp.Rtf;
temp.Dispose();
 

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

Back
Top