//Checks for valid input for Rx textboxes. Checks the box passed in through "tb, " //using different criteria based on parameter the box represents (determined by "box"). //Checks for valid ranges, does not check for valid increments. /// <summary> /// Checks for valid input for an Rx textbox /// </summary> /// <param name="tb">The box to check the contents of</param> /// <param name="box">The Rx parameter - Sphere, Cylinder, Axis or Add</param> /// <returns>True if the contents are valid, false otherwise</returns> /// <exception cref="System.FormatException">Thrown when the text is not a proper integer or real number</exception> private bool Rx_TextBox_Valid(TextBoxBase tb, RxBox box) { int pos = tb.Text.LastIndexOf('.'); float val; if (box == RxBox.Axis) { if (tb.TextLength == 0) //Blank { tb.Text = "0"; } try { //Is the contents a valid integer? val = Math.Abs(Convert.ToInt16(tb.Text)); } catch { return(false); } tb.DeselectAll(); tb.Text = val.ToString("0"); //Checks for valid range if (val > AXIS_MAX_VALUE) { return(false); } } else //Sphere, Cylinder or Add { if (tb.TextLength == 0) { tb.Text = "0.00"; } try { //Is the contents a valid real number? val = Convert.ToSingle(tb.Text); } catch { return(false); } tb.DeselectAll(); if (pos > -1) //Handle decimal { string ts = tb.Text.Substring(pos + 1); if (ts == "2" || ts == "7") { if (val < 0) { val -= 0.05F; } else { val += 0.05F; } } } // if(box == RxBox.Cyl) // val = -Math.Abs(val); // CYL is converted later if necessary tb.Text = val.ToString("0.00"); //Checks for valid range if (box == RxBox.Sphere) { if (val > SPHERE_MAX_VALUE) { return(false); } } else if (box == RxBox.Cyl) { if (-val > CYLINDER_MAX_VALUE) { return(false); } } else { if (val > ADD_MAX_VALUE) { return(false); } } } return(true); }