Added hovering color tracker
This commit is contained in:
55
Paint_2/Form1.Designer.cs
generated
55
Paint_2/Form1.Designer.cs
generated
@@ -71,10 +71,11 @@
|
||||
this.panel4 = new System.Windows.Forms.Panel();
|
||||
this.label14 = new System.Windows.Forms.Label();
|
||||
this.panel5 = new System.Windows.Forms.Panel();
|
||||
this.button17 = new System.Windows.Forms.Button();
|
||||
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();
|
||||
@@ -214,7 +215,7 @@
|
||||
// btnColorHistory4
|
||||
//
|
||||
this.btnColorHistory4.BackColor = System.Drawing.Color.Red;
|
||||
this.btnColorHistory4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
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.Name = "btnColorHistory4";
|
||||
@@ -226,7 +227,7 @@
|
||||
// btnColorHistory3
|
||||
//
|
||||
this.btnColorHistory3.BackColor = System.Drawing.Color.Red;
|
||||
this.btnColorHistory3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
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.Name = "btnColorHistory3";
|
||||
@@ -238,7 +239,7 @@
|
||||
// btnColorHistory2
|
||||
//
|
||||
this.btnColorHistory2.BackColor = System.Drawing.Color.Red;
|
||||
this.btnColorHistory2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
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.Name = "btnColorHistory2";
|
||||
@@ -250,7 +251,7 @@
|
||||
// btnColorHistory1
|
||||
//
|
||||
this.btnColorHistory1.BackColor = System.Drawing.Color.Green;
|
||||
this.btnColorHistory1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
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.Name = "btnColorHistory1";
|
||||
@@ -623,11 +624,12 @@
|
||||
// panel4
|
||||
//
|
||||
this.panel4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
||||
this.panel4.Controls.Add(this.btnSelectedColor);
|
||||
this.panel4.Controls.Add(this.lblSelectedColor);
|
||||
this.panel4.Controls.Add(this.label14);
|
||||
this.panel4.Location = new System.Drawing.Point(426, 606);
|
||||
this.panel4.Location = new System.Drawing.Point(382, 606);
|
||||
this.panel4.Name = "panel4";
|
||||
this.panel4.Size = new System.Drawing.Size(319, 50);
|
||||
this.panel4.Size = new System.Drawing.Size(363, 50);
|
||||
this.panel4.TabIndex = 31;
|
||||
//
|
||||
// label14
|
||||
@@ -643,27 +645,24 @@
|
||||
// panel5
|
||||
//
|
||||
this.panel5.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(31)))), ((int)(((byte)(31)))), ((int)(((byte)(31)))));
|
||||
this.panel5.Controls.Add(this.button17);
|
||||
this.panel5.Controls.Add(this.btnHoveringColor);
|
||||
this.panel5.Controls.Add(this.lblHoveringColor);
|
||||
this.panel5.Controls.Add(this.label15);
|
||||
this.panel5.Location = new System.Drawing.Point(12, 606);
|
||||
this.panel5.Name = "panel5";
|
||||
this.panel5.Size = new System.Drawing.Size(408, 50);
|
||||
this.panel5.Size = new System.Drawing.Size(370, 50);
|
||||
this.panel5.TabIndex = 32;
|
||||
//
|
||||
// button17
|
||||
// btnHoveringColor
|
||||
//
|
||||
this.button17.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(41)))), ((int)(((byte)(41)))), ((int)(((byte)(41)))));
|
||||
this.button17.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
||||
this.button17.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.button17.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(214)))), ((int)(((byte)(214)))), ((int)(((byte)(214)))));
|
||||
this.button17.Location = new System.Drawing.Point(301, 6);
|
||||
this.button17.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
|
||||
this.button17.Name = "button17";
|
||||
this.button17.Size = new System.Drawing.Size(95, 38);
|
||||
this.button17.TabIndex = 4;
|
||||
this.button17.Text = "Select";
|
||||
this.button17.UseVisualStyleBackColor = false;
|
||||
this.btnHoveringColor.BackColor = System.Drawing.Color.Green;
|
||||
this.btnHoveringColor.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
|
||||
this.btnHoveringColor.Font = new System.Drawing.Font("Cascadia Code", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.btnHoveringColor.Location = new System.Drawing.Point(309, -2);
|
||||
this.btnHoveringColor.Name = "btnHoveringColor";
|
||||
this.btnHoveringColor.Size = new System.Drawing.Size(55, 55);
|
||||
this.btnHoveringColor.TabIndex = 30;
|
||||
this.btnHoveringColor.UseVisualStyleBackColor = false;
|
||||
//
|
||||
// lblHoveringColor
|
||||
//
|
||||
@@ -689,6 +688,17 @@
|
||||
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);
|
||||
@@ -772,10 +782,11 @@
|
||||
private System.Windows.Forms.Panel panel4;
|
||||
private System.Windows.Forms.Label label14;
|
||||
private System.Windows.Forms.Panel panel5;
|
||||
private System.Windows.Forms.Button button17;
|
||||
private System.Windows.Forms.Label lblHoveringColor;
|
||||
private System.Windows.Forms.Label label15;
|
||||
private System.Windows.Forms.Timer tmrRefresh;
|
||||
private System.Windows.Forms.Button btnHoveringColor;
|
||||
private System.Windows.Forms.Button btnSelectedColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Paint_2
|
||||
List<PaintTool> toolList;
|
||||
bool drawing = false;
|
||||
Random rnd;
|
||||
Color hoveringColor;
|
||||
public PaintForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -29,6 +30,7 @@ namespace Paint_2
|
||||
toolList.Add(new Pencil());
|
||||
sketch = new Sketch(new Size((int)nupWidth.Value, (int)nupHeight.Value), toolList);
|
||||
canvas.Image = sketch.Drawing;
|
||||
tmrRefresh.Enabled = true;
|
||||
}
|
||||
private Point MousePositionToCanvasPosition()
|
||||
{
|
||||
@@ -39,7 +41,7 @@ namespace Paint_2
|
||||
{
|
||||
drawing = true;
|
||||
sketch.StartDrawing(MousePositionToCanvasPosition(), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), (int)nupPencilWidth.Value);
|
||||
tmrRefresh.Enabled = true;
|
||||
//tmrRefresh.Enabled = true;
|
||||
|
||||
List<Color> colorHistory = sketch.CurrentTool.GetLastColors(4);
|
||||
btnColorHistory1.BackColor = colorHistory[0];
|
||||
@@ -49,7 +51,7 @@ namespace Paint_2
|
||||
}
|
||||
private void canvas_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
tmrRefresh.Enabled = false;
|
||||
//tmrRefresh.Enabled = false;
|
||||
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
||||
drawing = false;
|
||||
RefreshUi();
|
||||
@@ -60,7 +62,6 @@ namespace Paint_2
|
||||
if (drawing)
|
||||
{
|
||||
sketch.AddDrawingPoint(MousePositionToCanvasPosition());
|
||||
|
||||
}
|
||||
RefreshUi();
|
||||
}
|
||||
@@ -83,6 +84,25 @@ namespace Paint_2
|
||||
{
|
||||
canvas.Image = sketch.Paint();
|
||||
lblSelectedColor.Text = ColorToString(sketch.CurrentTool.Color);
|
||||
btnSelectedColor.BackColor = sketch.CurrentTool.Color;
|
||||
hoveringColor = GetHoverColor();
|
||||
lblHoveringColor.Text = ColorToString(hoveringColor);
|
||||
btnHoveringColor.BackColor = hoveringColor;
|
||||
}
|
||||
private Color GetHoverColor()
|
||||
{
|
||||
Point cursorLocation = MousePositionToCanvasPosition();
|
||||
Color pixel;
|
||||
if (cursorLocation.X > 0 && cursorLocation.X < canvas.Width && cursorLocation.Y > 0 && cursorLocation.Y < canvas.Height)
|
||||
{
|
||||
pixel = (canvas.Image as Bitmap).GetPixel(cursorLocation.X, cursorLocation.Y);
|
||||
}
|
||||
else
|
||||
{
|
||||
pixel = Color.FromArgb(0x00,0x00,0x00);
|
||||
}
|
||||
return pixel;
|
||||
|
||||
}
|
||||
private void btnClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user