Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove an action from undo stack of a RichTextBox control?

It seems that there is this ClearUndo() method in a RichTextBox in Windows Forms (see system.windows.forms.textboxbase.).

I need something similar in RichTextBox Control. This is because (as it is mentioned here: Preventing a RichTextBox operation from being added to the control's Undo stack) every change is added to the RichTextBox's undo stack.

I like to override OnTextChanged event and remove some of these changes from Uno stack. How can I do that?

thanks.

like image 885
Ramin Avatar asked Nov 22 '12 19:11

Ramin


1 Answers

You can emulate ClearUndo() for WPF RichTextBox control with the following code:

richTextBox.IsUndoEnabled = false;
richTextBox.IsUndoEnabled = true;

But there's no way you can control any particular actions in the Undo list.

If you still want to implement your own Undo/Redo mechanism, the easiest and the most straightforward way is to store in an array the whole text of the control on each significant text change. But I would advise it only if you're not planning to edit large text with the control.

like image 152
Max Shmelev Avatar answered Sep 20 '22 23:09

Max Shmelev