问题描述
我正在做一个绘画应用程序,我可以直接在表单上绘制圆圈,调整大小并在我想要的时候改变颜色,现在我想要添加两个按钮来重做并撤消这些圆圈一,我将我的圈子存储在一个列表中,以便使用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 havezeros
推荐答案
撤消按钮将恢复最后一个圆圈列表,但也会将当前圈子保留在类似的重做列表列表中。
重做按钮将使用这两个列表执行相应的操作。
每个编辑器操作也将清除重做列表。
一个更难的解决方案:组织一些包含编辑器操作的撤消和重做列表,例如添加-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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!