如何在C#windows应用程序中实现撤消/重做功能? [英] How to implement undo/redo function in C# windows application ?

查看:156
本文介绍了如何在C#windows应用程序中实现撤消/重做功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..



我想在windows app中实现undo / redo选项。我在运行时添加和删除控件中创建了一个面板控件,因此需要根据添加或删除的控件实现undo / redo。如果我删除任何控件然后通过撤消操作它应该重新创建。如果有任何想法请分享。

提前致谢。



我尝试过:



我尝试了一些代码,但它适用于控件状态,而不是来自父级的添加和删除控件。

hi..

I want to implement undo/redo option in windows app. I create one panel control inside that adding and deleting controls at run time, so need to implement undo/redo according to added or deleted control. If i delete any control then by undo operation it should recreate. If anyone have any idea please share.
Thanks in advance.

What I have tried:

I tried some code but it works for controls state, not for add and delete control from parent.

推荐答案

删除时你可以保留一个标志在表中将其标记为已删除,在撤消时,您可以重置标志以再次重新显示记录。但是要实现这一切,您必须创建另一个表,记录最近所需的更改,因此您可以还原更改。您也可以锻炼更新和插入。这可能是最简单的方法。



没有尝试过这样做,所以我同意可以采用更好的方法,很快我们就会看到一些好的方法建议/解决方案。



在此期间,如果与您的问题相关,您可以查看以下文章 -

C#中的多级撤销和重做实现 - 第一部分(使用单个对象表示变更方法) [ ^ ]



希望,它有帮助:)
For deletion you can maintain a flag in the table to mark it as deleted and upon undo, you can reset the flag to reappear the record again. But for all this to happend you have to create another table which logs the recent required changes and accordingly you can revert the changes. You can workout for Update and Insert too. This could be the simplest approach to do this.

Haven't tried to do this ever so I agree there could be better approaches available and soon we may see some good suggestions/solutions.

In the meantime, you may check following article if it is relevant to your problem-
Multilevel Undo and Redo Implementation in C# - Part I (Using Single Object Representing Change Approach)[^]

Hope, it helps :)


这篇关于如何在C#windows应用程序中实现撤消/重做功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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