Exemple #1
0
 /// <summary>
 /// Purpose: to clear the values in both text boxes and return the focus
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BtnClear_Click(object sender, EventArgs e)
 {
     TxtDiameter.Clear();
     TxtTurns.Clear();
     TxtDiameter.Focus();
     return;
 }
Exemple #2
0
 /// <summary>
 /// Purpose: on key press enter, it will find out how many turns of the wheel it takes to make a mile
 /// </summary>
 /// <param name="sender">txtBdDiameter_KeyPress</param>
 /// <param name="e">not used</param>
 private void TxtBoxDiameter_KeyPress(object sender, KeyPressEventArgs e)
 {
     #region Variables
     double _circumfrance = 0.0;
     double _diameter     = 0.0;
     double _wheelTurns   = 0.0;
     #endregion Variables
     if (e.KeyChar == (char)Keys.Enter)
     {
         // 1) on enter stroke read data entered, store in _diameter
         double.TryParse(TxtDiameter.Text, out _diameter);
         if (_diameter <= 0) // some simple error correction
         {
             MessageBox.Show("That is an invalad entry, try again.");
             TxtDiameter.Clear();
             TxtTurns.Clear();
             TxtDiameter.Focus();
             return;
         }
         // 2) circumfrance = pi * diameter
         _circumfrance = Math.PI * _diameter;
         // 3) wheelTurns = mile / circumfrance
         _wheelTurns = MILE_INCHES / _circumfrance;
         // 4) display wheel turns in txtBxTurns
         TxtTurns.Text = string.Format("{0:f3}", _wheelTurns);
     }
 }