Pregunta

Quiero saber cuál es el camino más fácil para desarrollar un deshacer en C #

Tengo una aplicación de Windows Forms, en la ventana que tengo un formulario con una gran cantidad de cuadro de texto, cuadro de selección, casilla ...

después del llenado de usuario y haga clic en el botón Calcular, entonces el cálculo programa de acuerdo a todas las entradas y devolver un valor a la pantalla.

busco una manera fácil de guardar los estados después de cada calculte, y dar al usuario la abbility para devolver una, o más pasos hacia atrás.

gracias

¿Fue útil?

Solución

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.

Otros consejos

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 bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top