diff --git a/Paint_2/Form1.Designer.cs b/Paint_2/Form1.Designer.cs index 94a0af4..4ea2590 100644 --- a/Paint_2/Form1.Designer.cs +++ b/Paint_2/Form1.Designer.cs @@ -116,6 +116,7 @@ this.btnSave.TabIndex = 1; this.btnSave.Text = "Save"; this.btnSave.UseVisualStyleBackColor = false; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // // canvas // @@ -141,6 +142,7 @@ this.btnSaveCopy.TabIndex = 2; this.btnSaveCopy.Text = "Save a copy"; this.btnSaveCopy.UseVisualStyleBackColor = false; + this.btnSaveCopy.Click += new System.EventHandler(this.btnSaveCopy_Click); // // label1 // diff --git a/Paint_2/Form1.cs b/Paint_2/Form1.cs index 8ab2488..d28e1a0 100644 --- a/Paint_2/Form1.cs +++ b/Paint_2/Form1.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading; @@ -13,6 +14,7 @@ namespace Paint_2 { public partial class PaintForm : Form { + const string DEFAULT_FILEPATH = "C:/Paint2/Drawings/"; Sketch sketch; List toolList; bool drawing = false; @@ -99,7 +101,7 @@ namespace Paint_2 } else { - pixel = Color.FromArgb(0x00,0x00,0x00); + pixel = Color.FromArgb(0x00, 0x00, 0x00); } return pixel; @@ -151,11 +153,45 @@ namespace Paint_2 { G = 25; } - if(B > 255) + if (B > 255) { B = 255; } sketch.ChangePaintToolColor(Color.FromArgb(R, G, B)); } + + private void btnSave_Click(object sender, EventArgs e) + { + string fileName = tbxProjectName.Text; + Bitmap image = (Bitmap)canvas.Image; + + if (!Directory.Exists(DEFAULT_FILEPATH)) + { + Directory.CreateDirectory(DEFAULT_FILEPATH); + } + if (!Directory.Exists(DEFAULT_FILEPATH + fileName)) + { + Directory.CreateDirectory(DEFAULT_FILEPATH + fileName); + } + + image.Save(DEFAULT_FILEPATH + fileName + "/" + fileName + ".png", System.Drawing.Imaging.ImageFormat.Png); + } + + private void btnSaveCopy_Click(object sender, EventArgs e) + { + string fileName = tbxProjectName.Text + "_copy"; + Bitmap image = (Bitmap)canvas.Image; + + if (!Directory.Exists(DEFAULT_FILEPATH)) + { + Directory.CreateDirectory(DEFAULT_FILEPATH); + } + if (!Directory.Exists(DEFAULT_FILEPATH + fileName)) + { + Directory.CreateDirectory(DEFAULT_FILEPATH + fileName); + } + + image.Save(DEFAULT_FILEPATH + fileName + "/" + fileName + ".png", System.Drawing.Imaging.ImageFormat.Png); + } } }