Click here to Skip to main content
14,328,292 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello!

I have a RichTextBox control. I use it for syntax highlighting in my text.

The problem is: after a syntax is highlighted, when user press Ctrl+Z (calls Undo action)... control "unhighlights" my text.

For highlighting I use Select method and SelectionColor property. How to suppress writting actions into the undo stack of a RichTextBox during SelectionColor changes? Is it possible?work.


What I have tried:

I tried using the LockCurrentUndoUnit method on the highlight logic to solve this problem, but it did not work.
Posted
Updated 12-Jan-19 12:25pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

Rather than lock it delete the formatting undo unit triggered by a "spacebar" key down event before it gets buried requiring you dig/parse the undo pool. There might be a way to set up the undo tracking to omit the inclusion of formatting as well --been a while for me. Best wishes.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Set the UndoLimit property of your Textbox to 0 or IsUndoEnabled to False... Should work.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100