Exemple #1
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            double valueFromTextBox;

            try
            {
                if (String.IsNullOrEmpty(textBoxValue.Text))
                {
                    throw new Exception("Field cannot be empty!");
                }
                labelError.Text = "";
                Double.TryParse(textBoxValue.Text, out valueFromTextBox);
                _lengthConverter.SetLength(Double.Parse(textBoxValue.Text));
                if (comboBoxConvertFrom.SelectedItem == null || comboBoxConvertTo.SelectedItem == null)
                {
                    throw new ArgumentNullException(null, "Pick a unit!");
                }
                labelResult.Text = Math.Round(
                    _lengthConverter.HandleConverter(
                        comboBoxConvertFrom.SelectedItem.ToString(), comboBoxConvertTo.SelectedItem.ToString()), 2).ToString();
            }
            catch (ArgumentNullException ex)
            {
                labelError.Text = ex.Message;
            }
            catch (Exception ex)
            {
                labelError.Text = ex.Message;
            }
        }