From 975e47ac627252556e86e79d1869e5ebe3a2ee6e Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Wed, 9 Oct 2024 21:06:55 +0200 Subject: [PATCH] Minor improvements to color picker Somewhat related to #8887 --- src/ui/Forms/ColorChooser.cs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/ui/Forms/ColorChooser.cs b/src/ui/Forms/ColorChooser.cs index 6bfe44ed4..d16003883 100644 --- a/src/ui/Forms/ColorChooser.cs +++ b/src/ui/Forms/ColorChooser.cs @@ -223,8 +223,16 @@ namespace Nikse.SubtitleEdit.Forms } } + private void ShowHexColorCode(ColorHandler.Argb argb) { + if (_hexEditOn) + { + return; + } + + _tbHexCode.TextChanged -= TextBoxHexCodeTextChanged; + if (_showAlpha) { _tbHexCode.Text = $"{argb.Red:X2}{argb.Green:X2}{argb.Blue:X2}{argb.Alpha:X2}"; @@ -233,6 +241,8 @@ namespace Nikse.SubtitleEdit.Forms { _tbHexCode.Text = $"{argb.Red:X2}{argb.Green:X2}{argb.Blue:X2}"; } + + _tbHexCode.TextChanged += TextBoxHexCodeTextChanged; } private void SetHsvLabels(ColorHandler.Hsv hsv) @@ -511,7 +521,6 @@ namespace Nikse.SubtitleEdit.Forms this._tbHexCode.TabIndex = 58; this._tbHexCode.TextChanged += new System.EventHandler(this.TextBoxHexCodeTextChanged); this._tbHexCode.Enter += new System.EventHandler(this.TextBoxHexCodeEnter); - this._tbHexCode.KeyDown += new System.Windows.Forms.KeyEventHandler(this._tbHexCode_KeyDown); this._tbHexCode.Leave += new System.EventHandler(this.TextBoxHexCodeLeave); this._tbHexCode.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TbHexCodeMouseDown); this._tbHexCode.MouseUp += new System.Windows.Forms.MouseEventHandler(this._tbHexCode_MouseUp); @@ -929,6 +938,10 @@ namespace Nikse.SubtitleEdit.Forms { DialogResult = DialogResult.Cancel; } + else if (e.KeyCode == Keys.Enter) + { + buttonOK_Click(null, null); + } } protected override void Dispose(bool disposing) @@ -961,6 +974,12 @@ namespace Nikse.SubtitleEdit.Forms private void TextBoxHexCodeLeave(object sender, EventArgs e) { + if (_hexEditOn) + { + _hexEditOn = false; + CheckValidHexInput(); + } + _hexEditOn = false; _tbHexCode.BackColor = UiUtil.BackColor; } @@ -1085,17 +1104,5 @@ namespace Nikse.SubtitleEdit.Forms { _tbHexCode.MaxLength = _showAlpha ? 9 : 7; } - - private void _tbHexCode_KeyDown(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter && _hexEditOn) - { - CheckValidHexInput(); - if (_tbHexCode.BackColor != Configuration.Settings.Tools.ListViewSyntaxErrorColor) - { - DialogResult = DialogResult.OK; - } - } - } } }