How to remove an action from a RichTextBox control stack?

This ClearUndo() method ClearUndo() in RichTextBox on Windows Forms (see system.windows.forms.textboxbase. ).

I need something like this in RichTextBox Control . This is because (as mentioned here: Preventing the RichTextBox operation from being added to the Undo stacks of the control ), each change is added to the RichTextBox undo stack.

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

thanks.

+7
source share
1 answer

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

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

But you cannot control any specific actions in the Undo list.

If you still want to implement your own Undo/Redo mechanism, the simplest and easiest way is to store the entire text of the control in an array with every significant change to the text. But I would advise this only if you do not plan to edit the large text using the control.

+11
source

All Articles