Added the ability to not only have random colors

This commit is contained in:
2022-05-31 13:34:09 +02:00
parent 68310609b7
commit b1e0b5d618
3 changed files with 67 additions and 30 deletions

View File

@@ -39,6 +39,8 @@
this.panelFile = new System.Windows.Forms.Panel(); this.panelFile = new System.Windows.Forms.Panel();
this.label10 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label();
this.panelDrawing = new System.Windows.Forms.Panel(); 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.label11 = new System.Windows.Forms.Label();
this.panelSelectedColor = new System.Windows.Forms.Panel(); this.panelSelectedColor = new System.Windows.Forms.Panel();
this.btnSelectedColor = new System.Windows.Forms.Button(); this.btnSelectedColor = new System.Windows.Forms.Button();
@@ -68,10 +70,9 @@
this.btnSetColor = new System.Windows.Forms.Button(); this.btnSetColor = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.panelTools = new System.Windows.Forms.Panel(); this.panelTools = new System.Windows.Forms.Panel();
this.btnRandomColor = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.lsbTools = new System.Windows.Forms.ListBox(); 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(); ((System.ComponentModel.ISupportInitialize)(this.canvas)).BeginInit();
this.panelFile.SuspendLayout(); this.panelFile.SuspendLayout();
this.panelDrawing.SuspendLayout(); this.panelDrawing.SuspendLayout();
@@ -202,6 +203,24 @@
this.panelDrawing.Size = new System.Drawing.Size(228, 47); this.panelDrawing.Size = new System.Drawing.Size(228, 47);
this.panelDrawing.TabIndex = 30; 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 // label11
// //
this.label11.AutoSize = true; this.label11.AutoSize = true;
@@ -432,7 +451,7 @@
this.btnColorHistory4.BackColor = System.Drawing.Color.Red; this.btnColorHistory4.BackColor = System.Drawing.Color.Red;
this.btnColorHistory4.FlatStyle = System.Windows.Forms.FlatStyle.Popup; 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.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.Name = "btnColorHistory4";
this.btnColorHistory4.Size = new System.Drawing.Size(25, 25); this.btnColorHistory4.Size = new System.Drawing.Size(25, 25);
this.btnColorHistory4.TabIndex = 4; this.btnColorHistory4.TabIndex = 4;
@@ -444,7 +463,7 @@
this.btnColorHistory3.BackColor = System.Drawing.Color.Red; this.btnColorHistory3.BackColor = System.Drawing.Color.Red;
this.btnColorHistory3.FlatStyle = System.Windows.Forms.FlatStyle.Popup; 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.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.Name = "btnColorHistory3";
this.btnColorHistory3.Size = new System.Drawing.Size(25, 25); this.btnColorHistory3.Size = new System.Drawing.Size(25, 25);
this.btnColorHistory3.TabIndex = 3; this.btnColorHistory3.TabIndex = 3;
@@ -456,7 +475,7 @@
this.btnColorHistory2.BackColor = System.Drawing.Color.Red; this.btnColorHistory2.BackColor = System.Drawing.Color.Red;
this.btnColorHistory2.FlatStyle = System.Windows.Forms.FlatStyle.Popup; 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.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.Name = "btnColorHistory2";
this.btnColorHistory2.Size = new System.Drawing.Size(25, 25); this.btnColorHistory2.Size = new System.Drawing.Size(25, 25);
this.btnColorHistory2.TabIndex = 2; this.btnColorHistory2.TabIndex = 2;
@@ -478,7 +497,7 @@
this.btnColorHistory1.BackColor = System.Drawing.Color.Green; this.btnColorHistory1.BackColor = System.Drawing.Color.Green;
this.btnColorHistory1.FlatStyle = System.Windows.Forms.FlatStyle.Popup; 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.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.Name = "btnColorHistory1";
this.btnColorHistory1.Size = new System.Drawing.Size(25, 25); this.btnColorHistory1.Size = new System.Drawing.Size(25, 25);
this.btnColorHistory1.TabIndex = 0; 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.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.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.label2);
this.panelTools.Controls.Add(this.lsbTools); this.panelTools.Controls.Add(this.lsbTools);
this.panelTools.Controls.Add(this.button1); this.panelTools.Controls.Add(this.button1);
@@ -579,6 +599,20 @@
this.panelTools.Size = new System.Drawing.Size(163, 593); this.panelTools.Size = new System.Drawing.Size(163, 593);
this.panelTools.TabIndex = 31; 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 // label2
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
@@ -598,28 +632,10 @@
this.lsbTools.ItemHeight = 18; this.lsbTools.ItemHeight = 18;
this.lsbTools.Location = new System.Drawing.Point(10, 358); this.lsbTools.Location = new System.Drawing.Point(10, 358);
this.lsbTools.Name = "lsbTools"; 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.TabIndex = 32;
this.lsbTools.SelectedIndexChanged += new System.EventHandler(this.lsbTools_SelectedIndexChanged); 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 // PaintForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F);
@@ -705,6 +721,7 @@
private System.Windows.Forms.ListBox lsbTools; private System.Windows.Forms.ListBox lsbTools;
private System.Windows.Forms.Label lblHeight; private System.Windows.Forms.Label lblHeight;
private System.Windows.Forms.Label lblWidth; private System.Windows.Forms.Label lblWidth;
private System.Windows.Forms.Button btnRandomColor;
} }
} }

View File

@@ -24,6 +24,7 @@ namespace Paint_2
Sketch sketch; Sketch sketch;
List<PaintTool> toolList; List<PaintTool> toolList;
bool drawing = false; bool drawing = false;
bool randomColor = false;
Random rnd; Random rnd;
Color hoveringColor; Color hoveringColor;
public PaintForm() public PaintForm()
@@ -46,7 +47,14 @@ namespace Paint_2
private void canvas_MouseDown(object sender, MouseEventArgs e) private void canvas_MouseDown(object sender, MouseEventArgs e)
{ {
drawing = true; 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) private void canvas_MouseUp(object sender, MouseEventArgs e)
{ {
@@ -97,6 +105,16 @@ namespace Paint_2
lblWidth.Text = "Width: "+canvas.Width.ToString(); lblWidth.Text = "Width: "+canvas.Width.ToString();
lblHeight.Text = "Height: "+canvas.Height.ToString(); lblHeight.Text = "Height: "+canvas.Height.ToString();
if (randomColor)
{
btnRandomColor.ForeColor = Color.Green;
}
else
{
btnRandomColor.ForeColor = Color.Red;
}
} }
private Color GetHoverColor() private Color GetHoverColor()
{ {
@@ -219,5 +237,11 @@ namespace Paint_2
sketch.Resize(canvas.Size); sketch.Resize(canvas.Size);
RefreshUi(); RefreshUi();
} }
private void btnRandomColor_Click(object sender, EventArgs e)
{
randomColor = !randomColor;
RefreshUi();
}
} }
} }

View File

@@ -17,14 +17,12 @@ namespace Paint_2
{ {
List<PaintTool> _toolList; List<PaintTool> _toolList;
PaintTool _currentTool; PaintTool _currentTool;
Color _currentColor;
bool _isDrawing; bool _isDrawing;
Bitmap _drawing; Bitmap _drawing;
Size _sketchSize; Size _sketchSize;
string _name; string _name;
internal List<PaintTool> ToolList { get => _toolList; set => _toolList = value; } internal List<PaintTool> ToolList { get => _toolList; set => _toolList = value; }
public PaintTool CurrentTool { get => _currentTool; set => _currentTool = 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 bool IsDrawing { get => _isDrawing; set => _isDrawing = value; }
public Bitmap Drawing { get => _drawing; set => _drawing = value; } public Bitmap Drawing { get => _drawing; set => _drawing = value; }
public Size SketchSize { get => _sketchSize; set => _sketchSize = value; } public Size SketchSize { get => _sketchSize; set => _sketchSize = value; }
@@ -32,8 +30,6 @@ namespace Paint_2
public Sketch(Size sketchSize,List<PaintTool> toolList) public Sketch(Size sketchSize,List<PaintTool> toolList)
{ {
CurrentColor = Color.FromArgb(0xFF, 0xFF, 0xFF);
IsDrawing = false; IsDrawing = false;
SketchSize = sketchSize; SketchSize = sketchSize;
Drawing = new Bitmap(SketchSize.Width, SketchSize.Height); Drawing = new Bitmap(SketchSize.Width, SketchSize.Height);