diff --git a/Paint_2/Form1.Designer.cs b/Paint_2/Form1.Designer.cs index 020be4e..1de84a4 100644 --- a/Paint_2/Form1.Designer.cs +++ b/Paint_2/Form1.Designer.cs @@ -39,6 +39,8 @@ this.panelFile = new System.Windows.Forms.Panel(); this.label10 = new System.Windows.Forms.Label(); this.panelDrawing = new System.Windows.Forms.Panel(); + this.lblHeight = new System.Windows.Forms.Label(); + this.lblWidth = new System.Windows.Forms.Label(); this.label11 = new System.Windows.Forms.Label(); this.panelSelectedColor = new System.Windows.Forms.Panel(); this.btnSelectedColor = new System.Windows.Forms.Button(); @@ -68,10 +70,9 @@ this.btnSetColor = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.panelTools = new System.Windows.Forms.Panel(); + this.btnRandomColor = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); this.lsbTools = new System.Windows.Forms.ListBox(); - this.lblWidth = new System.Windows.Forms.Label(); - this.lblHeight = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit(); this.panelFile.SuspendLayout(); this.panelDrawing.SuspendLayout(); @@ -202,6 +203,24 @@ this.panelDrawing.Size = new System.Drawing.Size(228, 47); this.panelDrawing.TabIndex = 30; // + // lblHeight + // + this.lblHeight.AutoSize = true; + this.lblHeight.Location = new System.Drawing.Point(100, 24); + this.lblHeight.Name = "lblHeight"; + this.lblHeight.Size = new System.Drawing.Size(104, 18); + this.lblHeight.TabIndex = 34; + this.lblHeight.Text = "Height: 2000"; + // + // lblWidth + // + this.lblWidth.AutoSize = true; + this.lblWidth.Location = new System.Drawing.Point(100, 6); + this.lblWidth.Name = "lblWidth"; + this.lblWidth.Size = new System.Drawing.Size(96, 18); + this.lblWidth.TabIndex = 33; + this.lblWidth.Text = "width: 2000"; + // // label11 // this.label11.AutoSize = true; @@ -432,7 +451,7 @@ this.btnColorHistory4.BackColor = System.Drawing.Color.Red; this.btnColorHistory4.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnColorHistory4.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnColorHistory4.Location = new System.Drawing.Point(107, 45); + this.btnColorHistory4.Location = new System.Drawing.Point(101, 45); this.btnColorHistory4.Name = "btnColorHistory4"; this.btnColorHistory4.Size = new System.Drawing.Size(25, 25); this.btnColorHistory4.TabIndex = 4; @@ -444,7 +463,7 @@ this.btnColorHistory3.BackColor = System.Drawing.Color.Red; this.btnColorHistory3.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnColorHistory3.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnColorHistory3.Location = new System.Drawing.Point(76, 45); + this.btnColorHistory3.Location = new System.Drawing.Point(70, 45); this.btnColorHistory3.Name = "btnColorHistory3"; this.btnColorHistory3.Size = new System.Drawing.Size(25, 25); this.btnColorHistory3.TabIndex = 3; @@ -456,7 +475,7 @@ this.btnColorHistory2.BackColor = System.Drawing.Color.Red; this.btnColorHistory2.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnColorHistory2.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnColorHistory2.Location = new System.Drawing.Point(45, 45); + this.btnColorHistory2.Location = new System.Drawing.Point(39, 45); this.btnColorHistory2.Name = "btnColorHistory2"; this.btnColorHistory2.Size = new System.Drawing.Size(25, 25); this.btnColorHistory2.TabIndex = 2; @@ -478,7 +497,7 @@ this.btnColorHistory1.BackColor = System.Drawing.Color.Green; this.btnColorHistory1.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnColorHistory1.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnColorHistory1.Location = new System.Drawing.Point(14, 45); + this.btnColorHistory1.Location = new System.Drawing.Point(10, 45); this.btnColorHistory1.Name = "btnColorHistory1"; this.btnColorHistory1.Size = new System.Drawing.Size(25, 25); this.btnColorHistory1.TabIndex = 0; @@ -554,6 +573,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.btnRandomColor); this.panelTools.Controls.Add(this.label2); this.panelTools.Controls.Add(this.lsbTools); this.panelTools.Controls.Add(this.button1); @@ -579,6 +599,20 @@ this.panelTools.Size = new System.Drawing.Size(163, 593); this.panelTools.TabIndex = 31; // + // btnRandomColor + // + this.btnRandomColor.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(41)))), ((int)(((byte)(41)))), ((int)(((byte)(41))))); + this.btnRandomColor.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.btnRandomColor.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnRandomColor.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214))))); + this.btnRandomColor.Location = new System.Drawing.Point(131, 45); + this.btnRandomColor.Name = "btnRandomColor"; + this.btnRandomColor.Size = new System.Drawing.Size(25, 25); + this.btnRandomColor.TabIndex = 34; + this.btnRandomColor.Text = "Rnd"; + this.btnRandomColor.UseVisualStyleBackColor = false; + this.btnRandomColor.Click += new System.EventHandler(this.btnRandomColor_Click); + // // label2 // this.label2.AutoSize = true; @@ -598,28 +632,10 @@ 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, 218); + this.lsbTools.Size = new System.Drawing.Size(141, 200); this.lsbTools.TabIndex = 32; this.lsbTools.SelectedIndexChanged += new System.EventHandler(this.lsbTools_SelectedIndexChanged); // - // lblWidth - // - this.lblWidth.AutoSize = true; - this.lblWidth.Location = new System.Drawing.Point(100, 6); - this.lblWidth.Name = "lblWidth"; - this.lblWidth.Size = new System.Drawing.Size(96, 18); - this.lblWidth.TabIndex = 33; - this.lblWidth.Text = "width: 2000"; - // - // lblHeight - // - this.lblHeight.AutoSize = true; - this.lblHeight.Location = new System.Drawing.Point(100, 24); - this.lblHeight.Name = "lblHeight"; - this.lblHeight.Size = new System.Drawing.Size(104, 18); - this.lblHeight.TabIndex = 34; - this.lblHeight.Text = "Height: 2000"; - // // PaintForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F); @@ -705,6 +721,7 @@ private System.Windows.Forms.ListBox lsbTools; private System.Windows.Forms.Label lblHeight; private System.Windows.Forms.Label lblWidth; + private System.Windows.Forms.Button btnRandomColor; } } diff --git a/Paint_2/Form1.cs b/Paint_2/Form1.cs index 389e76c..dad0e82 100644 --- a/Paint_2/Form1.cs +++ b/Paint_2/Form1.cs @@ -24,6 +24,7 @@ namespace Paint_2 Sketch sketch; List toolList; bool drawing = false; + bool randomColor = false; Random rnd; Color hoveringColor; public PaintForm() @@ -46,7 +47,14 @@ namespace Paint_2 private void canvas_MouseDown(object sender, MouseEventArgs e) { drawing = true; - sketch.StartDrawing(MousePositionToCanvasPosition(), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), (int)nupPencilWidth.Value); + if (randomColor) + { + sketch.StartDrawing(MousePositionToCanvasPosition(), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), (int)nupPencilWidth.Value); + } + else + { + sketch.StartDrawing(MousePositionToCanvasPosition(),sketch.CurrentTool.Color, (int)nupPencilWidth.Value); + } } private void canvas_MouseUp(object sender, MouseEventArgs e) { @@ -97,6 +105,16 @@ namespace Paint_2 lblWidth.Text = "Width: "+canvas.Width.ToString(); lblHeight.Text = "Height: "+canvas.Height.ToString(); + + if (randomColor) + { + btnRandomColor.ForeColor = Color.Green; + } + else + { + btnRandomColor.ForeColor = Color.Red; + } + } private Color GetHoverColor() { @@ -219,5 +237,11 @@ namespace Paint_2 sketch.Resize(canvas.Size); RefreshUi(); } + + private void btnRandomColor_Click(object sender, EventArgs e) + { + randomColor = !randomColor; + RefreshUi(); + } } } diff --git a/Paint_2/Sketch.cs b/Paint_2/Sketch.cs index 6860d1e..f8a49c6 100644 --- a/Paint_2/Sketch.cs +++ b/Paint_2/Sketch.cs @@ -17,14 +17,12 @@ namespace Paint_2 { List _toolList; PaintTool _currentTool; - Color _currentColor; bool _isDrawing; Bitmap _drawing; Size _sketchSize; string _name; internal List ToolList { get => _toolList; set => _toolList = value; } public PaintTool CurrentTool { get => _currentTool; set => _currentTool = value; } - public Color CurrentColor { get => _currentColor; set => _currentColor = value; } public bool IsDrawing { get => _isDrawing; set => _isDrawing = value; } public Bitmap Drawing { get => _drawing; set => _drawing = value; } public Size SketchSize { get => _sketchSize; set => _sketchSize = value; } @@ -32,8 +30,6 @@ namespace Paint_2 public Sketch(Size sketchSize,List toolList) { - - CurrentColor = Color.FromArgb(0xFF, 0xFF, 0xFF); IsDrawing = false; SketchSize = sketchSize; Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);