From e428ad0ebf140d7641c8a3f810940658366124fb Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 17 May 2017 15:44:25 +0300 Subject: [PATCH] In color picker don't copy fields on double click --- ShareX.HelpersLib/Helpers/ColorHelpers.cs | 25 ++++++++++++--------- ShareX/Forms/ScreenColorPicker.cs | 27 ----------------------- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/ShareX.HelpersLib/Helpers/ColorHelpers.cs b/ShareX.HelpersLib/Helpers/ColorHelpers.cs index 55c6766b1..6270334ec 100644 --- a/ShareX.HelpersLib/Helpers/ColorHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ColorHelpers.cs @@ -308,22 +308,25 @@ public static bool ParseColor(string text, out Color color) { text = text.Trim(); - Match matchHex = Regex.Match(text, @"^(?:#|0x)?((?:[0-9A-F]{2}){3})$", RegexOptions.IgnoreCase); - - if (matchHex.Success) + if (text.Length <= 20) { - color = HexToColor(matchHex.Groups[1].Value); - return true; - } - else - { - Match matchRGB = Regex.Match(text, @"^(?:rgb\()?([1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\s|,)+([1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\s|,)+([1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\)?$"); + Match matchHex = Regex.Match(text, @"^(?:#|0x)?((?:[0-9A-F]{2}){3})$", RegexOptions.IgnoreCase); - if (matchRGB.Success) + if (matchHex.Success) { - color = Color.FromArgb(int.Parse(matchRGB.Groups[1].Value), int.Parse(matchRGB.Groups[2].Value), int.Parse(matchRGB.Groups[3].Value)); + color = HexToColor(matchHex.Groups[1].Value); return true; } + else + { + Match matchRGB = Regex.Match(text, @"^(?:rgb\()?([1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\s|,)+([1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])(?:\s|,)+([1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\)?$"); + + if (matchRGB.Success) + { + color = Color.FromArgb(int.Parse(matchRGB.Groups[1].Value), int.Parse(matchRGB.Groups[2].Value), int.Parse(matchRGB.Groups[3].Value)); + return true; + } + } } } diff --git a/ShareX/Forms/ScreenColorPicker.cs b/ShareX/Forms/ScreenColorPicker.cs index e4cd0c6ef..694e47537 100644 --- a/ShareX/Forms/ScreenColorPicker.cs +++ b/ShareX/Forms/ScreenColorPicker.cs @@ -47,14 +47,6 @@ public ScreenColorPicker(bool checkClipboard = false) UpdateControls(false); - foreach (Control control in Controls) - { - if (control is NumericUpDown || control is TextBox) - { - control.DoubleClick += CopyToClipboard; - } - } - if (checkClipboard) { if (Clipboard.ContainsText()) @@ -69,25 +61,6 @@ public ScreenColorPicker(bool checkClipboard = false) } } - private void CopyToClipboard(object sender, EventArgs e) - { - string text = ""; - - if (sender is NumericUpDown) - { - text = ((NumericUpDown)sender).Value.ToString(); - } - else if (sender is TextBox) - { - text = ((TextBox)sender).Text; - } - - if (!string.IsNullOrEmpty(text)) - { - ClipboardHelpers.CopyText(text); - } - } - private void UpdateColor(int x, int y) { UpdateColor(x, y, CaptureHelpers.GetPixelColor(x, y));