How to implement 'undo' operation in .net windows application?

后端 未结 9 1254
无人共我
无人共我 2020-12-04 22:35

Assume that, a win form has certain input fields and user enters/re-enters some data.

How to retain data previously entered by \'undo\' operation?

Just I wan

9条回答
  •  失恋的感觉
    2020-12-04 23:35

    I'm not sure if WinForms/.Net has some type of built-in Undo feature that you can take advantage of. But what you are really looking for is a Stack datastructure to help you manage a list of actions. You'll need to create some type of "action" object to represent the actions that a user could do and as they progress through the application you'll need to push these actions onto the Stack. When they hit the undo button, or Ctrl-Z or whatever method of initiating the undo action you'll pop off the current action and restore the application state to the previous action.

    This is a very basic and high level overview of how this would work but I imagine that implementing such a feature can get quite complex. Just imagine how it needs to work for a program like Adobe Photoshop. :O

提交回复
热议问题