Pergunta

I want to know what is the easy way to develop an undo in c#

i have a windows form application, in the window i have a form with a lot of text box , select box , checkbox ...

after the user fill in and click on calculate button, then the program calculate according to all the inputs and return a value to the screen.

i search an easy way to save the states after every calculte , and give the user the abbility to return one, or more steps back .

thanks

Foi útil?

Solução

I don't think there is any standard built-in, but you can find some frameworks to do it yourself: The Undo Framework with a sample for Forms: Samples for the Undo Framework

There is also the Monitored Undo Framework.

Outras dicas

The easiest way is to simply save the input text somewhere.

You could get more fancy by encoding, somehow, only the text that has changed from the last time the input was saved. For example, you could store only new text that was added along with the position it was added. Or you could store only the position and length of text that was deleted. But that's more complex and the effect is the same.

While a text box does have a simple undo feature built in, if that doesn't work for you, you'll just have to save the text at each undo point. It's easy, simple, and necessary.

If you are using Textbox. You can Undo it by 1 step back by using `Undo() method n

txtBoxResult.Undo();

A simple implementation would be a stack. As the user performs operations, push the current value onto the stack. As they 'undo', pop values off of the stack.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top