public KeyBoardKey(CustomizedKey key, IKeyHandler keyHandler) : this() { this.Key = key; this.KeyHandler = keyHandler; this.KeyButton.Text = key.KeyChar; }
/// <summary> /// Creates the key. /// </summary> /// <param name="keyHandler">The key handler.</param> /// <param name="key">The key.</param> /// <returns></returns> public static Controls.KeyBoardKey CreateKey(this IKeyHandler keyHandler, CustomizedKey key, int rowIndex = 0, int colIndex = 0) { var keyControl = new KeyBoardKey(key, keyHandler); keyControl.GridRowIndex = rowIndex; keyControl.GridColumnIndex = colIndex; return keyControl; }
public void HandleChar(CustomizedKey key) { var charWord = key.KeyChar; if (HasError) { if (charWord == KeyBoardWords.Clear) { ClearDisplayText(); } _lastKey = key; return; } if (key.Type == KeyType.Number) { SendingOperating = false; if (ClearTextBeforeNumbersInput) { DisplayResult = string.Empty; ClearTextBeforeNumbersInput = false; } if (charWord == KeyBoardWords.Clear) { ClearDisplayText(); _lastKey = key; return; } else if (charWord == KeyBoardWords.Dot) { if (!DisplayResult.Contains(KeyBoardWords.Dot)) { if (!SendingOperating) { if (displayResult.Length == 0) { displayResult += KeyBoardWords.Zero; } DisplayResult = displayResult + KeyBoardWords.Dot; } } } else { if (charWord == KeyBoardWords.DoubleZero || charWord == KeyBoardWords.Zero) { if (displayResult.Length > 0) { if (displayResult[0].ToString() == KeyBoardWords.Zero) { if (!displayResult.Contains(KeyBoardWords.Dot)) { _lastKey = key; return; } } } else { _lastKey = key; DisplayResult = KeyBoardWords.Zero; return; } } else { if (displayResult.Length == 1 && displayResult[0].ToString() == KeyBoardWords.Zero) { displayResult = string.Empty; } } if (!SendingOperating) { DisplayResult = displayResult + charWord; lastStepValue = double.Parse(displayResult); } } } else if (key.Type == KeyType.Operator) { if (key.Opeartor == KeyOperator.Close) { _lastKey = key; OnConfirmed(EventArgs.Empty); return; } if (key.Opeartor == KeyOperator.Del) { if (displayResult.Length > 1) { DisplayResult = displayResult.Remove(displayResult.Length - 1, 1); } if (displayResult.Length == 1) { DisplayResult = KeyBoardWords.Zero; } } else if (key.Opeartor == KeyOperator.Clear) { _lastKey = key; ClearDisplayText(); return; } else { ShowResult(key.Opeartor); } } _lastKey = key; }