winform C#上所有控件的撤消/重做功能 [英] Undo/Redo functionality for all controls on winform C#

查看:1046
本文介绍了winform C#上所有控件的撤消/重做功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



我的winform上有很多可编辑的控件(文本框,数据网格视图,组合框等)。目前,如果我选择一个特定的控件并按Ctrl + Z或+ Y,它仅适用于该特定的选定控件。但我们的要求是对所有控件使用撤消/重做功能。



例如:如果用户修改了30个控件,那么当他执行Undo / redo时,应该一个接一个地反映所有控件的变化。它就像你完成撤消/重做最后一个修改过的控件一样。



如何实现这个目标?请建议。

谢谢

Hello friends,

I have lot of editable controls(textboxes, datagrid views, comboboxes etc) on my winform. Currently if i select a particular control and press Ctrl+Z or +Y, it works only for that particular selected control. But our requirement is to use the Undo/redo functionality for all the controls.

For eg.: If user has modified 30 controls then when he does Undo/redo, the changes should get reflected for all controls one after another. Its like till u finished undo-ing/redo-ing the last modified control.

How to achieve this? Please suggest.
Thanks

推荐答案

您必须记住控件接受用户输入的顺序。请务必设置表单的 KeyPreview属性,以便您可以在几个Undos的序列中适当地改变焦点。



或者做得对,数据绑定所有控件并处理底层数据。 CP上有一篇关于撤销/重做缓冲框架的文章。不要害怕与 Mementos 上其他文章的链接断开。搜索效果很好。



祝你好运。
You would have to remember the order in which controls have accepted user input. Be sure to have the form's KeyPreview property set so you can change focus whenever appropriate during a sequence of several Undos.

Or do it right, data-bind all the controls and work on the underlying data. There's an article on an Undo/Redo Buffer Framework here at CP. Don't be afraid of the broken link to the other article on Mementos. The search works quite well.

Good luck.


这篇关于winform C#上所有控件的撤消/重做功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆