一种在Windows应用程序中撤消和重做的方法c# [英] A way to Undo and Redo in windows application c#

查看:77
本文介绍了一种在Windows应用程序中撤消和重做的方法c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个绘画应用程序,我可以直接在表单上绘制圆圈,调整大小并在我想要的时候改变颜色,现在我想要添加两个按钮来重做并撤消这些圆圈一,我将我的圈子存储在一个列表中,以便使用Paint函数重绘
,我可以得到一些帮助吗?

Iam doing a paint application where i can draw circles on the form directly, resize them and change their colors when i want, now i'm thinking of way to add two buttons to redo and undo these circles one by one, i store my circles in a list in order to redraw them using the Paint function, can i get some help ?

  private void button2_Click(object sender,EventArgs e)

        {

$
            circles = myStack.Pop();

           图形a = CreateGraphics();

            a.DrawEllipse(pen,startx,starty,circles.width,circles.height);



        }


        private void button1_Click(object sender,EventArgs e)

        {

            myStack.Push(圈子);

           图形a = CreateGraphics();

            a.DrawEllipse(b,startx,starty,circles.width,circles.height);

        }

  private void button2_Click(object sender, EventArgs e)
        {

            circles = myStack.Pop();
            Graphics a = CreateGraphics();
            a.DrawEllipse(pen, startx, starty, circles.width, circles.height);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            myStack.Push(circles);
            Graphics a = CreateGraphics();
            a.DrawEllipse(b, startx, starty, circles.width, circles.height);
        }

这些是我的想法,但是关于myStack.Push(圈子)存在问题;

those are my thoughts, but there is a problem regarding the myStack.Push(circles);

圈子在列表圈中有值包含of 

circles have values in the list circles consists of 

Int x,y;

Int Height,Width;

Int Height,Width;

他们有值列表当我将它们添加到堆栈并通过断点在Watch上观察时,变量往往有

they have values in the list when i add them to the stack and watch them on the Watch via a break point the variables tend to have zeros

推荐答案

我认为既然你的形象并不复杂,那么你可以简单地组织以前的圆圈列表(例如
'列表与LT;列表与LT;圈>>'的)。在每个操作之前,将新副本(当前圆圈)添加到此列表中。保持合理的步骤数。确保创建圆圈副本,因为不应共享这些对象。

I think that since your image is not complex, then you can simply organize a collection of previous lists of circles (such as ‘List<List<Circle>>’). Before each operation, add a new copy (the current circles) to this list. Keep a reasonable number of steps. Make sure that you create copies of circles, since these objects should not be shared.

撤消按钮将恢复最后一个圆圈列表,但也会将当前圈子保留在类似的重做列表列表中。

重做按钮将使用这两个列表执行相应的操作。

每个编辑器操作也将清除重做列表。

一个更难的解决方案:组织一些包含编辑器操作的撤消和重做列表,例如添加-circle,move-circle,set-color等。此层次结构中的每个对象都将具有与执行的操作相关联的相应数据成员
以及撤消重做(或只是执行) 虚拟功能。按钮将调用相应的功能,并将在列表之间移动操作。

A more difficult solution: organise some Undo and Redo lists containing the editor operations, such as add-circle, move-circle, set-colour, etc. Each object in this hierarchy will have the corresponding data members associated with the performed operation, and also the Undo and Redo (or just Perform) virtual functions. The buttons will call the corresponding functions and will move the operations between the lists.

如果您的编辑器具有缩放和滚动功能,那么您也可以包含这些详细信息。


这篇关于一种在Windows应用程序中撤消和重做的方法c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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