From 8b7c63a40ba172362181ff295bdb2a1527d80733 Mon Sep 17 00:00:00 2001 From: maxluli Date: Wed, 25 May 2022 15:11:29 +0200 Subject: [PATCH] Added the full ability to set the color --- Paint_2/Form1.Designer.cs | 66 +++++++++++++++++++++++++++++---------- Paint_2/Form1.cs | 43 +++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 16 deletions(-) diff --git a/Paint_2/Form1.Designer.cs b/Paint_2/Form1.Designer.cs index ef23ccf..94a0af4 100644 --- a/Paint_2/Form1.Designer.cs +++ b/Paint_2/Form1.Designer.cs @@ -67,15 +67,17 @@ this.panel2 = new System.Windows.Forms.Panel(); this.label11 = new System.Windows.Forms.Label(); this.panel3 = new System.Windows.Forms.Panel(); + this.button1 = new System.Windows.Forms.Button(); + this.btnSetColor = new System.Windows.Forms.Button(); this.label13 = new System.Windows.Forms.Label(); this.panel4 = new System.Windows.Forms.Panel(); + this.btnSelectedColor = new System.Windows.Forms.Button(); this.label14 = new System.Windows.Forms.Label(); this.panel5 = new System.Windows.Forms.Panel(); this.btnHoveringColor = new System.Windows.Forms.Button(); this.lblHoveringColor = new System.Windows.Forms.Label(); this.label15 = new System.Windows.Forms.Label(); this.tmrRefresh = new System.Windows.Forms.Timer(this.components); - this.btnSelectedColor = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nupHeight)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nupWidth)).BeginInit(); @@ -290,7 +292,7 @@ this.tbxColorHex.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214))))); this.tbxColorHex.Location = new System.Drawing.Point(10, 116); this.tbxColorHex.Name = "tbxColorHex"; - this.tbxColorHex.Size = new System.Drawing.Size(141, 25); + this.tbxColorHex.Size = new System.Drawing.Size(85, 25); this.tbxColorHex.TabIndex = 10; this.tbxColorHex.Text = "#FFFFFF"; // @@ -327,7 +329,7 @@ 0, 0}); this.nupRed.Name = "nupRed"; - this.nupRed.Size = new System.Drawing.Size(141, 21); + this.nupRed.Size = new System.Drawing.Size(85, 21); this.nupRed.TabIndex = 13; this.nupRed.Value = new decimal(new int[] { 255, @@ -348,7 +350,7 @@ 0, 0}); this.nupGreen.Name = "nupGreen"; - this.nupGreen.Size = new System.Drawing.Size(141, 21); + this.nupGreen.Size = new System.Drawing.Size(85, 21); this.nupGreen.TabIndex = 14; this.nupGreen.Value = new decimal(new int[] { 255, @@ -369,7 +371,7 @@ 0, 0}); this.nupBlue.Name = "nupBlue"; - this.nupBlue.Size = new System.Drawing.Size(141, 21); + this.nupBlue.Size = new System.Drawing.Size(85, 21); this.nupBlue.TabIndex = 15; this.nupBlue.Value = new decimal(new int[] { 255, @@ -582,6 +584,8 @@ // panel3 // this.panel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31))))); + this.panel3.Controls.Add(this.button1); + this.panel3.Controls.Add(this.btnSetColor); this.panel3.Controls.Add(this.btnFill); this.panel3.Controls.Add(this.label13); this.panel3.Controls.Add(this.btnClear); @@ -611,6 +615,34 @@ this.panel3.Size = new System.Drawing.Size(163, 642); this.panel3.TabIndex = 31; // + // button1 + // + this.button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(41)))), ((int)(((byte)(41)))), ((int)(((byte)(41))))); + this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.button1.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214))))); + this.button1.Location = new System.Drawing.Point(101, 167); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(56, 83); + this.button1.TabIndex = 31; + this.button1.Text = "Set"; + this.button1.UseVisualStyleBackColor = false; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // btnSetColor + // + this.btnSetColor.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(41)))), ((int)(((byte)(41)))), ((int)(((byte)(41))))); + this.btnSetColor.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.btnSetColor.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnSetColor.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214))))); + this.btnSetColor.Location = new System.Drawing.Point(101, 113); + this.btnSetColor.Name = "btnSetColor"; + this.btnSetColor.Size = new System.Drawing.Size(56, 31); + this.btnSetColor.TabIndex = 30; + this.btnSetColor.Text = "Set"; + this.btnSetColor.UseVisualStyleBackColor = false; + this.btnSetColor.Click += new System.EventHandler(this.btnSetColor_Click); + // // label13 // this.label13.AutoSize = true; @@ -632,6 +664,17 @@ this.panel4.Size = new System.Drawing.Size(363, 50); this.panel4.TabIndex = 31; // + // btnSelectedColor + // + this.btnSelectedColor.BackColor = System.Drawing.Color.Green; + this.btnSelectedColor.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.btnSelectedColor.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnSelectedColor.Location = new System.Drawing.Point(302, -2); + this.btnSelectedColor.Name = "btnSelectedColor"; + this.btnSelectedColor.Size = new System.Drawing.Size(55, 55); + this.btnSelectedColor.TabIndex = 31; + this.btnSelectedColor.UseVisualStyleBackColor = false; + // // label14 // this.label14.AutoSize = true; @@ -688,17 +731,6 @@ this.tmrRefresh.Interval = 1; this.tmrRefresh.Tick += new System.EventHandler(this.tmrRefresh_Tick); // - // btnSelectedColor - // - this.btnSelectedColor.BackColor = System.Drawing.Color.Green; - this.btnSelectedColor.FlatStyle = System.Windows.Forms.FlatStyle.Popup; - this.btnSelectedColor.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.btnSelectedColor.Location = new System.Drawing.Point(302, -2); - this.btnSelectedColor.Name = "btnSelectedColor"; - this.btnSelectedColor.Size = new System.Drawing.Size(55, 55); - this.btnSelectedColor.TabIndex = 31; - this.btnSelectedColor.UseVisualStyleBackColor = false; - // // PaintForm // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 22F); @@ -787,6 +819,8 @@ private System.Windows.Forms.Timer tmrRefresh; private System.Windows.Forms.Button btnHoveringColor; private System.Windows.Forms.Button btnSelectedColor; + private System.Windows.Forms.Button btnSetColor; + private System.Windows.Forms.Button button1; } } diff --git a/Paint_2/Form1.cs b/Paint_2/Form1.cs index ebc5c6a..8ab2488 100644 --- a/Paint_2/Form1.cs +++ b/Paint_2/Form1.cs @@ -114,5 +114,48 @@ namespace Paint_2 { sketch.ChangePaintToolWidth((int)nupPencilWidth.Value); } + + private void btnSetColor_Click(object sender, EventArgs e) + { + string value = tbxColorHex.Text; + value = value.Replace("#", String.Empty); + int R, G, B; + try + { + R = Convert.ToInt32(value[0] + value[1]); + G = Convert.ToInt32(value[2] + value[3]); + B = Convert.ToInt32(value[4] + value[5]); + } + catch (Exception exception) + { + MessageBox.Show("Please enter a valid hexadecimal value"); + tbxColorHex.Text = "#FFFFFF"; + R = 255; + G = 255; + B = 255; + } + sketch.ChangePaintToolColor(Color.FromArgb(R, G, B)); + } + + private void button1_Click(object sender, EventArgs e) + { + int R, G, B; + R = (int)nupRed.Value; + G = (int)nupGreen.Value; + B = (int)nupBlue.Value; + if (R > 255) + { + R = 255; + } + if (G > 255) + { + G = 25; + } + if(B > 255) + { + B = 255; + } + sketch.ChangePaintToolColor(Color.FromArgb(R, G, B)); + } } }