public GoToHexBoxDialog() { InitializeComponent(); radioButtonDec.CheckedChanged += UpdateStates; radioButtonHex.CheckedChanged += UpdateStates; radioButtonOct.CheckedChanged += UpdateStates; textBoxOffset.TextChanged += UpdateStates; this.Shown += UpdateStates; _lastGoToType = GoToType; SetStrings(); }
void UpdateStates(object sender, EventArgs e) { string textOffset = textBoxOffset.Text; if (textOffset.Length == 0 || (textOffset.Length >= 2 && textOffset.Substring(0, 2) == "0x")) { buttonOk.Enabled = false; return; } if (sender is TextBox || sender is GoToHexBoxDialog) { long oldValue = Value; if (textOffset.Substring(0, 1) == "+" || textOffset.Substring(0, 1) == "-") { _direction = textOffset.Substring(0, 1); textOffset = textOffset.Remove(0, 1); } try { long value = Convert.ToInt64(textOffset, (int)_goToType); if (_direction == "-") { if ((Value - value) < Minimum) { buttonOk.Enabled = false; return; } _relativeValue = -value; } else if (_direction == "+") { if ((Value + value) > Maximum) { buttonOk.Enabled = false; return; } _relativeValue = +value; } else { _relativeValue = 0; Value = value; } buttonOk.Enabled = true; // textBoxOffset.Text = direction + ConvertValue(Value.ToString(), (int)_goToType, (int)_goToType); } catch (Exception ex) { buttonOk.Enabled = false; Value = oldValue; } _direction = ""; } else if (sender is RadioButton) { textOffset = textBoxOffset.Text; if (textOffset.Substring(0, 1) == "+" || textOffset.Substring(0, 1) == "-") { _direction = textOffset.Substring(0, 1); textOffset = textOffset.Remove(0, 1); } else { _direction = string.Empty; } textBoxOffset.Text = _direction + ConvertValue(textOffset, (int)_lastGoToType, (int)_goToType); _lastGoToType = _goToType; } }
private void radioButtonOct_CheckedChanged(object sender, EventArgs e) { _goToType = GoToType.Octal; }
private void radioButtonDec_CheckedChanged(object sender, EventArgs e) { _goToType = GoToType.Decimal; }