Added the undo feature
This commit is contained in:
@@ -105,5 +105,21 @@ namespace Paint_2
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
if (Drawings.Count > 1)
|
||||
{
|
||||
Drawings.RemoveAt(Drawings.Count - 1);
|
||||
Colors.RemoveAt(Colors.Count - 1);
|
||||
Widths.RemoveAt(Widths.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Drawings.Clear();
|
||||
Colors.Clear();
|
||||
Widths.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
19
Paint_2/Form1.Designer.cs
generated
19
Paint_2/Form1.Designer.cs
generated
@@ -73,6 +73,7 @@
|
||||
this.btnRandomColor = new System.Windows.Forms.Button();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.lsbTools = new System.Windows.Forms.ListBox();
|
||||
this.btnUndo = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit();
|
||||
this.panelFile.SuspendLayout();
|
||||
this.panelDrawing.SuspendLayout();
|
||||
@@ -573,6 +574,7 @@
|
||||
//
|
||||
this.panelTools.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.panelTools.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
||||
this.panelTools.Controls.Add(this.btnUndo);
|
||||
this.panelTools.Controls.Add(this.btnRandomColor);
|
||||
this.panelTools.Controls.Add(this.label2);
|
||||
this.panelTools.Controls.Add(this.lsbTools);
|
||||
@@ -632,10 +634,24 @@
|
||||
this.lsbTools.ItemHeight = 18;
|
||||
this.lsbTools.Location = new System.Drawing.Point(10, 358);
|
||||
this.lsbTools.Name = "lsbTools";
|
||||
this.lsbTools.Size = new System.Drawing.Size(141, 200);
|
||||
this.lsbTools.Size = new System.Drawing.Size(141, 182);
|
||||
this.lsbTools.TabIndex = 32;
|
||||
this.lsbTools.SelectedIndexChanged += new System.EventHandler(this.lsbTools_SelectedIndexChanged);
|
||||
//
|
||||
// btnUndo
|
||||
//
|
||||
this.btnUndo.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(41)))), ((int)(((byte)(41)))), ((int)(((byte)(41)))));
|
||||
this.btnUndo.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
||||
this.btnUndo.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.btnUndo.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214)))));
|
||||
this.btnUndo.Location = new System.Drawing.Point(3, 547);
|
||||
this.btnUndo.Name = "btnUndo";
|
||||
this.btnUndo.Size = new System.Drawing.Size(157, 43);
|
||||
this.btnUndo.TabIndex = 35;
|
||||
this.btnUndo.Text = "Undo";
|
||||
this.btnUndo.UseVisualStyleBackColor = false;
|
||||
this.btnUndo.Click += new System.EventHandler(this.btnUndo_Click);
|
||||
//
|
||||
// PaintForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F);
|
||||
@@ -722,6 +738,7 @@
|
||||
private System.Windows.Forms.Label lblHeight;
|
||||
private System.Windows.Forms.Label lblWidth;
|
||||
private System.Windows.Forms.Button btnRandomColor;
|
||||
private System.Windows.Forms.Button btnUndo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,11 @@ namespace Paint_2
|
||||
result += "R:" + color.R + " G:" + color.G + " B:" + color.B;
|
||||
return result;
|
||||
}
|
||||
private void ForceRefresh()
|
||||
{
|
||||
canvas.Image = sketch.ForcePaint();
|
||||
RefreshUi();
|
||||
}
|
||||
private void RefreshUi()
|
||||
{
|
||||
canvas.Image = sketch.Paint();
|
||||
@@ -114,7 +119,6 @@ namespace Paint_2
|
||||
{
|
||||
btnRandomColor.ForeColor = Color.Red;
|
||||
}
|
||||
|
||||
}
|
||||
private Color GetHoverColor()
|
||||
{
|
||||
@@ -135,7 +139,7 @@ namespace Paint_2
|
||||
private void btnClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
sketch.Clear();
|
||||
RefreshUi();
|
||||
ForceRefresh();
|
||||
}
|
||||
|
||||
private void nupPencilWidth_ValueChanged(object sender, EventArgs e)
|
||||
@@ -243,5 +247,11 @@ namespace Paint_2
|
||||
randomColor = !randomColor;
|
||||
RefreshUi();
|
||||
}
|
||||
|
||||
private void btnUndo_Click(object sender, EventArgs e)
|
||||
{
|
||||
sketch.Undo();
|
||||
ForceRefresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Paint_2
|
||||
void Start(Color color,int width);
|
||||
void Stop(Point point);
|
||||
void Add(Point point);
|
||||
void Undo();
|
||||
void Clear();
|
||||
List<Color> GetLastColors(int colorNumber);
|
||||
void Paint(Bitmap canvas);
|
||||
|
||||
@@ -106,5 +106,21 @@ namespace Paint_2
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
if (Drawings.Count > 1)
|
||||
{
|
||||
Drawings.RemoveAt(Drawings.Count -1);
|
||||
Colors.RemoveAt(Colors.Count -1);
|
||||
Widths.RemoveAt(Widths.Count -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Drawings.Clear();
|
||||
Colors.Clear();
|
||||
Widths.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@ namespace Paint_2
|
||||
Console.WriteLine("Oooops...");
|
||||
}
|
||||
}
|
||||
public void Undo()
|
||||
{
|
||||
CurrentTool.Undo();
|
||||
}
|
||||
public void StartDrawing(Point location,Color color,int width)
|
||||
{
|
||||
CurrentTool.Start(color,width);
|
||||
@@ -87,7 +91,6 @@ namespace Paint_2
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);
|
||||
foreach (PaintTool tool in ToolList)
|
||||
{
|
||||
tool.Clear();
|
||||
@@ -95,6 +98,12 @@ namespace Paint_2
|
||||
}
|
||||
public Bitmap Paint()
|
||||
{
|
||||
CurrentTool.Paint(Drawing);
|
||||
return Drawing;
|
||||
}
|
||||
public Bitmap ForcePaint()
|
||||
{
|
||||
Drawing = new Bitmap(SketchSize.Width,SketchSize.Height);
|
||||
foreach (PaintTool tool in ToolList)
|
||||
{
|
||||
tool.Paint(Drawing);
|
||||
|
||||
Reference in New Issue
Block a user