Cancel the TextChanging event

SyntaxEditor for Windows Forms Forum

Posted 20 years ago by Campion
Avatar
In 2.0, how about allowing for a handler of the TextChanging event to cancel the event? Currently, DocumentModificationEventArgs does not have a Cancel property. Or, is there another way to accomplish cancel functionality that is recommended, today?

Also, the SyntaxEditor.AcceptTab property should be renamed to AcceptsTab for consistency with .NET (ex. see TextBoxBase class).

Comments (5)

Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
What scenarios would you want to cancel modifications? One thing I fear is that by cancelling something like an undo/redo operation, you would corrupt the undo stacks because the items would already have been popped. There are other situations like that too.

That property will be renamed for the 2.0 release.


Actipro Software Support

Posted 20 years ago by Campion
Avatar
The scenario is similar to a source code control (SCC) plug-in to Visual Studio. If the user doesn't have the file checked out and starts editing it (TextChanging fires), the user is asked if the file should be checked-out. If the user says no, the edit will not happen.
Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
One thing that I'm very concerned about is things like undo operations or other undo grouped text changes. If you cancel something that the internal control relies on happening, you could really mess up the internal structures.


Actipro Software Support

Posted 20 years ago by Eric J. Smith
Avatar
Couldn't you set the document to readonly mode when it's not checked out and then trap the keypress event? When the user presses a key in the document and it's read only, you ask them if they want to check out the file and if so, you remove the read only flag and process their key press action.

I haven't tried it, but it seems like that would work.

Eric J. Smith
Posted 20 years ago by Campion
Avatar
Yeah, that's a valid approach. However, KeyPress doesn't fire for the delete key (or backspace key for this control). So, the code gets more involved because one needs to check the KeyDown event as well.

I ended up using a combination of TextChanging and TextChanged because it was slightly simpler. "e.Cancel = true;" in the TextChanging event would be better (hint, hint) :-)
The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.