-1

I am programming a game, in which i sometimes need to undo some steps, is there a direct way to do this? I tried putting the controls in data structures, stacks and lists and so, but things are too complicated in my game. thanks

Sujood
  • 15
  • 5
  • 1
    What do you mean by "changes" and "form state"? Most likely the answer is in any case that you have to do it yourself. – Sami Kuhmonen Mar 26 '16 at 14:54
  • When the user in my game changes things, i would like to give him the chance to undo this. Which means I would like to get the previous state the form was in. – Sujood Mar 26 '16 at 15:24
  • Still, what "state"? What things are changed? Position? Text? Values? Colors? Sizes? You'll have to save this "state" somehow to be able to go back anyway. – Sami Kuhmonen Mar 26 '16 at 15:28

1 Answers1

0

No, there is not a built-in way to do this; you have to code it yourself. I would suggest creating a class FormState which has members to represent the values of each control on the form whose state you want to save. Then add methods to copy the form values to and from the form. Finally, make a stack data structure in your program. Whenever the user changes something on the form, create a new instance of the FormState, call the method to transfer the current form state to the FormState object, and push it on the stack. If the user presses undo, pop the last state off the stack and call the method to restore the form controls from the FormState class. That's really all there is to it.

Brian Rogers
  • 125,747
  • 31
  • 299
  • 300