The main color picker is also drag and drop now

This commit is contained in:
2022-06-09 13:27:11 +02:00
parent 44956fbc59
commit 97d800af1f
3 changed files with 51 additions and 18 deletions

View File

@@ -42,7 +42,8 @@
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.tmrRefresh = new System.Windows.Forms.Timer(this.components);
this.tmrRefreshBars = new System.Windows.Forms.Timer(this.components);
this.tmrRefreshMain = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.pbxColor)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbxSelectedColor)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nupRed)).BeginInit();
@@ -62,7 +63,8 @@
this.pbxColor.Size = new System.Drawing.Size(255, 255);
this.pbxColor.TabIndex = 0;
this.pbxColor.TabStop = false;
this.pbxColor.Click += new System.EventHandler(this.pbxColor_Click);
this.pbxColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbxColor_MouseDown);
this.pbxColor.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pbxColor_MouseUp);
//
// pbxSelectedColor
//
@@ -217,10 +219,15 @@
this.label4.TabIndex = 26;
this.label4.Text = "A";
//
// tmrRefresh
// tmrRefreshBars
//
this.tmrRefresh.Interval = 1;
this.tmrRefresh.Tick += new System.EventHandler(this.tmrRefresh_Tick);
this.tmrRefreshBars.Interval = 1;
this.tmrRefreshBars.Tick += new System.EventHandler(this.tmrRefresh_Tick);
//
// tmrRefreshMain
//
this.tmrRefreshMain.Interval = 1;
this.tmrRefreshMain.Tick += new System.EventHandler(this.tmrRefreshMain_Tick);
//
// ColorPicker
//
@@ -280,6 +287,7 @@
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Timer tmrRefresh;
private System.Windows.Forms.Timer tmrRefreshBars;
private System.Windows.Forms.Timer tmrRefreshMain;
}
}

View File

@@ -142,13 +142,20 @@ namespace Paint_2
private void pbxColor_Click(object sender, EventArgs e)
{
cursorLocation = pbxColor.PointToClient(MousePosition);
SelectedColor = (pbxColor.Image as Bitmap).GetPixel(cursorLocation.X, cursorLocation.Y);
if (cursorLocation.X >= 0 && cursorLocation.X < 255 && cursorLocation.Y >= 0 && cursorLocation.Y < 255)
{
Color newColor = (pbxColor.Image as Bitmap).GetPixel(cursorLocation.X, cursorLocation.Y);
if (newColor.R > 0 || newColor.R == 0 && SelectedColor.R < 5) //This is a bad way of fixing a bug where sometimes the mouse inputs are 0,0,0
{
SelectedColor = newColor;
}
RefreshUi();
}
}
private void pbxSliderRed_Click(object sender, EventArgs e)
{
int mouseX = pbxSliderRed.PointToClient(MousePosition).X;
if (mouseX >= 0 && mouseX <= 255)
if (mouseX >= 0 && mouseX < 255)
{
SelectedColor = Color.FromArgb(SelectedColor.A, mouseX, SelectedColor.G, SelectedColor.B);
}
@@ -157,7 +164,8 @@ namespace Paint_2
private void pbxSliderSaturation_Click(object sender, EventArgs e)
{
int mouseY = pbxSliderSaturation.PointToClient(MousePosition).Y;
if (mouseY >= 0 && mouseY <= 255) {
if (mouseY >= 0 && mouseY <= 255)
{
SelectedColor = Color.FromArgb(mouseY, SelectedColor.R, SelectedColor.G, SelectedColor.B);
}
RefreshUi();
@@ -271,15 +279,29 @@ namespace Paint_2
pbxSliderSaturation_Click(sender, e);
pbxSliderRed_Click(sender, e);
}
private void tmrRefreshMain_Tick(object sender, EventArgs e)
{
pbxColor_Click(sender, e);
}
private void SliderMouseDown(object sender, MouseEventArgs e)
{
tmrRefresh.Enabled = true;
tmrRefreshBars.Enabled = true;
}
private void SliderMouseUp(object sender, MouseEventArgs e)
{
tmrRefresh.Enabled = false;
tmrRefreshBars.Enabled = false;
}
private void pbxColor_MouseDown(object sender, MouseEventArgs e)
{
tmrRefreshMain.Enabled = true;
}
private void pbxColor_MouseUp(object sender, MouseEventArgs e)
{
tmrRefreshMain.Enabled = false;
}
}
}

View File

@@ -117,7 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="tmrRefresh.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="tmrRefreshBars.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="tmrRefreshMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>177, 17</value>
</metadata>
</root>