C# 在 Windows 窗体应用程序中撤消
我想知道在 C# 中开发撤消的简单方法是什么
我有一个 Windows 表单应用程序,在窗口中我有一个带有很多文本框、选择框、复选框...
用户填写并单击后的表单在计算按钮上, 然后程序根据所有输入进行计算并将一个值返回到屏幕。
我寻找一种简单的方法来在每次计算后保存状态,并让用户能够返回一个或多个步骤。
谢谢
I want to know what is the easy way to develop an undo in c#
i have a windows form application, in the window i have a form with a lot of text box , select box , checkbox ...
after the user fill in and click on calculate button,
then the program calculate according to all the inputs and return a value to the screen.
i search an easy way to save the states after every calculte , and give the user the abbility to return one, or more steps back .
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为没有任何标准的内置功能,但您可以找到一些框架来自己完成此操作: 撤消框架,包含表单示例:撤消框架示例
还有受监控的撤消框架。
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.
一个简单的实现是堆栈。当用户执行操作时,将当前值压入堆栈。当它们“撤消”时,将从堆栈中弹出值。
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.
最简单的方法是将输入文本保存在某处。
您可以通过某种方式仅编码自上次保存输入以来已更改的文本来获得更多奇特的效果。例如,您可以仅存储添加的新文本及其添加位置。或者您可以仅存储已删除文本的位置和长度。但这更复杂,而且效果是一样的。
虽然文本框确实具有内置的简单撤消功能,但如果这对您不起作用,您只需在每个撤消点保存文本即可。这很容易、简单而且必要。
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.
如果您使用的是文本框。 向后撤消 1 步
您可以使用 `Undo() 方法 n
txtBoxResult.Undo();
If you are using Textbox. You can Undo it by 1 step back by using `Undo() method n
txtBoxResult.Undo();
已经很晚了,但昨天刚刚收到朋友的询问。
我在 richtextbox 中开发了这个简单的撤消重做功能。是的,有很多更好的方法,但它只是作为一种快速解决方案可以使用。
Its pretty late, but just got a query from friend yesterday.
I developed this simple undo redo functionality in richtextbox. Yes there are many better ways but just as a quick solution it can be used.