# HG changeset patch # User IBBoard # Date 1261656272 0 # Node ID 727c1b0e49a65d7d23bd84dfa20d7698078c2f4f # Parent c1a3993297b10ffe200e41e6bb0cf1cfec165940 Fixes #115: Typing number for equipment amount doesn't update Okay button * Remove KeyDown capture code (AcceptButton functionality captures the key press first) * Add ProcessDialogKey method that uses ValueChanged helper class to determine whether the control changes when we force an update New functionality is that the values can be typed and changed by pressing Enter, then a second Enter will accept the changes and close the dialog. If no changes were made then pressing Enter once accepts changes and closes the dialog. diff -r c1a3993297b1 -r 727c1b0e49a6 UI/EquipmentAmountControl.Designer.cs --- a/UI/EquipmentAmountControl.Designer.cs Thu Dec 24 10:52:03 2009 +0000 +++ b/UI/EquipmentAmountControl.Designer.cs Thu Dec 24 12:04:32 2009 +0000 @@ -93,7 +93,6 @@ this.percentage.Size = new System.Drawing.Size(105, 20); this.percentage.TabIndex = 4; this.percentage.ValueChanged += new System.EventHandler(this.percentage_ValueChanged); - this.percentage.KeyDown += new System.Windows.Forms.KeyEventHandler(this.percentage_KeyDown); // // lblPercentSign // diff -r c1a3993297b1 -r 727c1b0e49a6 UI/EquipmentAmountControl.cs --- a/UI/EquipmentAmountControl.cs Thu Dec 24 10:52:03 2009 +0000 +++ b/UI/EquipmentAmountControl.cs Thu Dec 24 12:04:32 2009 +0000 @@ -10,6 +10,7 @@ using IBBoard.Lang; using IBBoard.Limits; using IBBoard.Windows.Forms.I18N; +using IBBoard.Windows.Forms.Util; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Util; @@ -171,16 +172,6 @@ OnValueChanged(); } - private void percentage_KeyDown(object sender, KeyEventArgs e) - { - Console.WriteLine("Keycode: "+e.KeyCode); - - if (e.KeyCode == Keys.Enter) - { - PerformPercentageValueChanged(); - } - } - private void SetNumericValueFromPercentage() { numeric.ValueChanged -= numeric_ValueChanged; @@ -346,5 +337,38 @@ { OnValueChanged(); } + + protected override bool ProcessDialogKey(Keys keyData) + { + bool processed = false; + + if (keyData == Keys.Enter) + { + if (numeric.Focused) + { + processed = ForceUpDownControlUpdate(numeric); + } + else if (percentage.Focused) + { + processed = ForceUpDownControlUpdate(percentage); + } + } + + if (!processed) + { + processed = base.ProcessDialogKey(keyData); + } + + return processed; + } + + private bool ForceUpDownControlUpdate(NumericUpDown control) + { + ControlValueChangedChecker checker = new ControlValueChangedChecker(); + control.ValueChanged += checker.ValueChanged; + decimal val = control.Value; + control.ValueChanged -= checker.ValueChanged; + return checker.valueChanged; + } } }