From 42d8fdd15ec52a959169be3574924508ede99d27 Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Mon, 29 Mar 2021 22:57:10 +0200 Subject: [PATCH] Fix for #303 where the combobox is editable, it does change the drawing a bit. [skip ci] --- .../Forms/ResizeSettingsForm.Designer.cs | 29 +++++++++-------- src/Greenshot/Forms/ResizeSettingsForm.cs | 32 ++++++++++--------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/Greenshot/Forms/ResizeSettingsForm.Designer.cs b/src/Greenshot/Forms/ResizeSettingsForm.Designer.cs index 689fe263c..e2f9a6c74 100644 --- a/src/Greenshot/Forms/ResizeSettingsForm.Designer.cs +++ b/src/Greenshot/Forms/ResizeSettingsForm.Designer.cs @@ -19,6 +19,7 @@ * along with this program. If not, see . */ +using System.Windows.Forms; using Greenshot.Base.Controls; namespace Greenshot.Forms { @@ -65,7 +66,7 @@ namespace Greenshot.Forms { this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 6; this.buttonOK.UseVisualStyleBackColor = true; - this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + this.buttonOK.Click += new System.EventHandler(this.ButtonOK_Click); // // buttonCancel // @@ -108,8 +109,8 @@ namespace Greenshot.Forms { this.textbox_height.Name = "textbox_height"; this.textbox_height.Size = new System.Drawing.Size(69, 20); this.textbox_height.TabIndex = 3; - this.textbox_height.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textbox_KeyUp); - this.textbox_height.Validating += new System.ComponentModel.CancelEventHandler(this.textbox_Validating); + this.textbox_height.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Textbox_KeyUp); + this.textbox_height.Validating += new System.ComponentModel.CancelEventHandler(this.Textbox_Validating); // // textbox_width // @@ -117,8 +118,8 @@ namespace Greenshot.Forms { this.textbox_width.Name = "textbox_width"; this.textbox_width.Size = new System.Drawing.Size(69, 20); this.textbox_width.TabIndex = 1; - this.textbox_width.KeyUp += new System.Windows.Forms.KeyEventHandler(this.textbox_KeyUp); - this.textbox_width.Validating += new System.ComponentModel.CancelEventHandler(this.textbox_Validating); + this.textbox_width.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Textbox_KeyUp); + this.textbox_width.Validating += new System.ComponentModel.CancelEventHandler(this.Textbox_Validating); // // combobox_width // @@ -127,19 +128,21 @@ namespace Greenshot.Forms { this.combobox_width.Name = "combobox_width"; this.combobox_width.Size = new System.Drawing.Size(65, 21); this.combobox_width.TabIndex = 2; - // - // combobox_height - // - this.combobox_height.FormattingEnabled = true; + this.combobox_width.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + // + // combobox_height + // + this.combobox_height.FormattingEnabled = true; this.combobox_height.ItemHeight = 13; this.combobox_height.Location = new System.Drawing.Point(165, 38); this.combobox_height.Name = "combobox_height"; this.combobox_height.Size = new System.Drawing.Size(65, 21); this.combobox_height.TabIndex = 4; - // - // ResizeSettingsForm - // - this.AcceptButton = this.buttonOK; + this.combobox_height.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + // + // ResizeSettingsForm + // + this.AcceptButton = this.buttonOK; this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.CancelButton = this.buttonCancel; diff --git a/src/Greenshot/Forms/ResizeSettingsForm.cs b/src/Greenshot/Forms/ResizeSettingsForm.cs index 06952272c..7ef60442d 100644 --- a/src/Greenshot/Forms/ResizeSettingsForm.cs +++ b/src/Greenshot/Forms/ResizeSettingsForm.cs @@ -53,15 +53,16 @@ namespace Greenshot.Forms textbox_height.Text = effect.Height.ToString(); _newWidth = effect.Width; _newHeight = effect.Height; - combobox_width.SelectedIndexChanged += combobox_SelectedIndexChanged; - combobox_height.SelectedIndexChanged += combobox_SelectedIndexChanged; + combobox_width.SelectedIndexChanged += Combobox_SelectedIndexChanged; + combobox_height.SelectedIndexChanged += Combobox_SelectedIndexChanged; checkbox_aspectratio.Checked = effect.MaintainAspectRatio; } - private void buttonOK_Click(object sender, EventArgs e) + private void ButtonOK_Click(object sender, EventArgs e) { - if (_newWidth != _effect.Width || _newHeight != _effect.Height) + const double tolerance = 3 * double.Epsilon; + if (Math.Abs(_newWidth - _effect.Width) > tolerance || Math.Abs(_newHeight - _effect.Height) > tolerance) { _effect.Width = (int) _newWidth; _effect.Height = (int) _newHeight; @@ -72,16 +73,17 @@ namespace Greenshot.Forms private static bool Validate(object sender) { - if (sender is TextBox textbox) + if (sender is not TextBox textBox) { - if (!double.TryParse(textbox.Text, out var numberEntered)) - { - textbox.BackColor = Color.Red; - return false; - } - - textbox.BackColor = Color.White; + return true; } + if (!double.TryParse(textBox.Text, out _)) + { + textBox.BackColor = Color.Red; + return false; + } + + textBox.BackColor = Color.White; return true; } @@ -116,7 +118,7 @@ namespace Greenshot.Forms textbox_height.Text = ((int) displayValue).ToString(); } - private void textbox_KeyUp(object sender, KeyEventArgs e) + private void Textbox_KeyUp(object sender, KeyEventArgs e) { if (!Validate(sender)) { @@ -186,7 +188,7 @@ namespace Greenshot.Forms } } - private void textbox_Validating(object sender, System.ComponentModel.CancelEventArgs e) + private void Textbox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { Validate(sender); } @@ -196,7 +198,7 @@ namespace Greenshot.Forms /// /// /// - private void combobox_SelectedIndexChanged(object sender, EventArgs e) + private void Combobox_SelectedIndexChanged(object sender, EventArgs e) { if (Validate(textbox_width)) {