Реализуй условие:
Функция отмены и повтора действий в кнопку
B_CancelAction
B_BackAction


Вот исходный код программы графического редактора в C# WF:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Практ_2_неделя_2__Задание_2_
{
    public partial class Form1 : Form
    {
        Stack<Action> drawActions = new Stack<Action>();
        Stack<Action> eraseActions = new Stack<Action>();

        public Form1()
        {
            InitializeComponent();
            SetSize();
            graphics.Clear(BackColor);
            pictureBox1.Image = map;
        }

        

        bool Mouse = false;
        Bitmap map;
        Graphics graphics;
        Pen pen = new Pen(Color.Black, 3f);
        Pen erase = new Pen(DefaultBackColor, 50);
        Point px, py;
        int index;
        int x,y,sX,sY,cX,cY;

        ColorDialog cd = new ColorDialog();
        Color new_color;


        private void SetSize()
        {
            Rectangle rectangle = Screen.PrimaryScreen.Bounds;
            map = new Bitmap(rectangle.Width, rectangle.Height);
            graphics = Graphics.FromImage(map); 

            pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
            pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
        }
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            Mouse = true;
            py = e.Location;

            cX = e.X;
            cY = e.Y;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (Mouse)
            {
                if (index == 1)
                {
                    px = e.Location;
                    graphics.DrawLine(pen, px, py);
                    py=px;
                }
                if (index == 2)
                {
                    px = e.Location;
                    graphics.DrawLine(erase, px, py);
                    py = px;
                }
            }
            pictureBox1.Refresh();
            x = e.X;
            y = e.Y;
            sX = e.X - cX;
            sY = e.Y - cY;
        }

        private void B_Ellipse_Click(object sender, EventArgs e)
        {
            index = 3;
        }

        private void B_Rectangle_Click(object sender, EventArgs e)
        {
            index = 4;
        }

        private void B_Line_Click(object sender, EventArgs e)
        {
            index = 5;
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            Mouse = false;

            sX = x - cX;
            sY = y - cY;

            if (index == 3)
            {
                graphics.DrawEllipse(pen, cX, cY, sX, sY);
            }
            if (index == 4)
            {
                graphics.DrawRectangle(pen, cX, cY, sX, sY);
            }
            if (index == 5)
            {
                graphics.DrawLine(pen, cX, cY, x, y);
            }
        }

        private void B_CancelAction_Click(object sender, EventArgs e)
        {
            
        }

        private void B_BackAction_Click(object sender, EventArgs e)
        {

        }

        private void B_SelectedColor_Click(object sender, EventArgs e)
        {
            if(colorDialog1.ShowDialog() == DialogResult.OK)
            {
                pen.Color = colorDialog1.Color;
                ((Button)sender).BackColor = colorDialog1.Color;
            }
        }
        private void B_SelectedColorMenu_Click(object sender, EventArgs e)
        {
            cd.ShowDialog();
            new_color = cd.Color;
            pictureBox1.BackColor = cd.Color;

            pen.Color = cd.Color;
            B_SelectedColor.BackColor = cd.Color;
        }

        private void B_Clear_Click(object sender, EventArgs e)
        {
            graphics.Clear(pictureBox1.BackColor);
            pictureBox1.Image = map;
        }

        private void B_Save_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "JPG(*.JPG)|*.jpg";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK && pictureBox1.Image != null)
            {
                pictureBox1.Image.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }

        private void B_Eraser_Click(object sender, EventArgs e)
        {
            index = 2;
        }

        private void B_Pen_Click(object sender, EventArgs e)
        {
            index = 1;
        }
    }
}