/// <summary> /// This is the reset method which clears the form whenever the click button is pressed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ResetButton_Click(object sender, EventArgs e) { HeightTextBox.Clear(); WeightTextBox.Clear(); resultTextBox.Clear(); BMIProgressBar.Hide(); }
private void CalculateBMIButton_Click(object sender, EventArgs e) { int height = 0; float weight = 0.0f; float bmi = 0.0f; try { height = int.Parse(HeightTextBox.Text); } catch { MessageBox.Show("拜託請輸入身高!"); HeightTextBox.Text = ""; //TextBox清空 HeightTextBox.Focus(); //游標位置 return; } try { weight = float.Parse(WeightTextBox.Text); } catch { MessageBox.Show("拜託請輸入體重!"); WeightTextBox.Text = ""; //TextBox清空 WeightTextBox.Focus(); //游標位置 return; } bmi = weight / ((height / 100.0f) * (height / 100.0f)); MessageBox.Show(string.Format("BMI:{0}", bmi.ToString("#.##"))); }
/// <summary> /// Method for clearing the textboxes in the form /// </summary> private void ClearForm() { WeightTextBox.Clear(); HeightTextBox.Clear(); //BMITextbox.Clear(); CalculateButton.Enabled = false; }
private void CalculateBMIButton_Click(object sender, EventArgs e) { double bmi = 0.0; double height = 0.0; double weight = 0.0; try { height = double.Parse(HeightTextBox.Text); } catch { MessageBox.Show("好好輸入身高可以嗎?"); HeightTextBox.Text = string.Empty; HeightTextBox.Focus(); return; } try { weight = double.Parse(WeightTextBox.Text); } catch { MessageBox.Show("好好輸入體重可以嗎?"); WeightTextBox.Text = string.Empty; WeightTextBox.Focus(); return; } height = height / 100.0; bmi = weight / (height * height); MessageBox.Show(string.Format("BMI: {0}", bmi.ToString("#.##"))); }
private bool IsValid() { var valid = true; if (NameTextBox.IsNullOrEmpty()) { NameTextBox.HintText.Foreground = ColorConstants.WarningRed; valid = false; } if (HeightTextBox.IsNullOrEmpty()) { HeightTextBox.HintText.Foreground = ColorConstants.WarningRed; valid = false; } if (WeightTextBox.IsNullOrEmpty()) { WeightTextBox.HintText.Foreground = ColorConstants.WarningRed; valid = false; } if (PositionComboBox.SelectedItem == null || RoleComboBox.SelectedItem == null) { valid = false; } return(valid); }
/// <summary> /// Clearing user inputs /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ResetButton_Click(object sender, EventArgs e) { HeightTextBox.Clear(); WeightTextBox.Clear(); BMIResultTextBox.Clear(); BMIScaleTextBox.Clear(); }
private void BMI_CalculatorButton_Click(object sender, EventArgs e) { if (this.ActiveError == false) { // create a reference to the sender object // and tell c-sharp that it is a button Button buttonClicked = (Button)sender; if (String.Equals(HeightTextBox.Text, "0")) { HeightTextBox.Clear(); } if (String.Equals(WeightTextBox.Text, "0")) { WeightTextBox.Clear(); } if (TextBoxFocus == true) { string HeightResult = HeightTextBox.Text; // read the string in the TextBox HeightResult += buttonClicked.Text; // add the text of the button clicked to the currentResult HeightTextBox.Text = HeightResult; // update the ResultTextBox this.ActiveControl = HeightTextBox; } else if (TextBoxFocus == false) { string WeightResult = WeightTextBox.Text; // read the string in the TextBox WeightResult += buttonClicked.Text; // add the text of the button clicked to the currentResult WeightTextBox.Text = WeightResult; // update the ResultTextBox this.ActiveControl = WeightTextBox; } } }
/// <summary> /// This method clears all the fields in the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ClearButton_Click_1(object sender, EventArgs e) { HeightTextBox.Clear(); WeightTextBox.Clear(); BMIResultTextBox.Clear(); BMIScaleTextBox.Clear(); HeightTextBox.Focus(); }
/// <summary> /// This method sets the background color to white and clears all textboxes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void clearButton_Click(object sender, EventArgs e) { HeightTextBox.Clear(); WeightTextBox.Clear(); BMITextbox.Clear(); BMIScaleMultiLineTextBox.Clear(); BMIScaleMultiLineTextBox.BackColor = Color.White; }
/// <summary> /// This is the where the reset button clears all the current information in each text box. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ResetButton_Click(object sender, EventArgs e) { WeightTextBox.Clear(); HeightTextBox.Clear(); BMIResultTextBox.Clear(); MetricRadioButton.Checked = false; ImperialRadioButton.Checked = true; ProgressBar.Value = 10; }
private void CancelButton_Click(object sender, RoutedEventArgs e) { BMIStatusIcon.Source = new BitmapImage(new Uri("/Images/BMIIcons/bmi-underweight-icon.png", UriKind.Relative)); BMIStatusText.Text = "Недостаточный"; BMIStatusArrow.RenderTransform = new TranslateTransform(48, 0); BMIStatusNumber.Text = "0.0"; HeightTextBox.Clear(); WeightTextBox.Clear(); }
/// <summary> /// Set controls value as defult /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ResetButton_Click(object sender, EventArgs e) { HeightTextBox.Clear(); WeightTextBox.Clear(); BmiTextBox.Clear(); ResultTextBox.Clear(); BmiProgressBar.Value = 0; ImperialRadioButton.Checked = true; ImperialRadioButton.Focus(); }
// CLEAR BUTTON private void ClearButton_Click_1(object sender, EventArgs e) { //clear fields HeightTextBox.Clear(); WeightTextBox.Clear(); ResultTextBox.Clear(); ResultInfoTextBox.Clear(); //enable textboxes HeightTextBox.Enabled = true; WeightTextBox.Enabled = true; }
/// <summary> /// This is an event handler to trigger a Click Event that will reset all of radio buttons and text boxes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ResetButton_Click(object sender, EventArgs e) { //Clear the textboxes WeightTextBox.Clear(); HeightTextBox.Clear(); BMIResultTextBox.Clear(); //Change the radio buttons to their original state ImpericalRadioButton.Checked = true; MetricRadioButton.Checked = false; //Hide error label BMIResultLabel.Visible = false; }
private void CancelButton_Click(object sender, RoutedEventArgs e) { BMRTextBlock.Text = "0"; SittingActivityTextBlock.Text = $"Сидячий образ: 0"; LowActivityTextBlock.Text = $"Маленькая активность: 0"; MediumActivityTextBlock.Text = $"Средняя активность: 0"; HighActivityTextBlock.Text = $"Высокая активность: 0"; MaxActivityTextBlock.Text = $"Максимальная активность 0"; HeightTextBox.Clear(); WeightTextBox.Clear(); AgeTextBox.Clear(); }
private void CalculateBMIButton_Click(object sender, EventArgs e) { int height = 0; float weight = 0.0f; float bmi = 0.0f; try { height = int.Parse(HeightTextBox.Text); } catch { MessageBox.Show("請輸入身高!!"); HeightTextBox.Text = ""; HeightTextBox.Focus(); return; } try { weight = float.Parse(WeightTextBox.Text); } catch { MessageBox.Show("請輸入體重!!"); WeightTextBox.Text = ""; WeightTextBox.Focus(); return; } bmi = weight / ((height / 100.0f) * (height / 100.0f)); //TODO 如果bmi大於24 或 bmi 小於 18 不健康 //TODO 顯示不健康的提示 //TODO 不然顯示健康的提示 if (bmi >= 18.5 && bmi <= 24.9) { MessageBox.Show(string.Format("BMI:{0}", bmi.ToString("#.##"))); BmiLabel.Text = ("BMI:" + bmi.ToString("#.##")); StatusLabel.Text = ("健康狀態:非常健康"); } else { MessageBox.Show(string.Format("BMI:{0}", bmi.ToString("#.##"))); BmiLabel.Text = ("BMI:" + bmi.ToString("#.##")); StatusLabel.Text = ("健康狀態:不健康唷"); } }
/// <summary> /// This method checks of the value entered is valid. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonCalculate_Click(object sender, EventArgs e) { try { height = Convert.ToDouble(HeightTextBox.Text); weight = Convert.ToDouble(WeightTextBox.Text); CalculateBMI(height, weight); } catch (Exception) { MessageBox.Show("Invalid number"); HeightTextBox.Clear(); WeightTextBox.Clear(); HeightTextBox.Focus(); } }
private void BmiButton_Click(object sender, EventArgs e) { float height = 0.0f; float weight = 0.0f; float bmi = 0.0f; try { height = float.Parse(HeightTextBox.Text); } catch { BmiStatusLabel.Text = "請輸入身高!"; BmiStatusLabel.ForeColor = Color.Blue; HeightTextBox.Text = ""; //TextBox清空 HeightTextBox.Focus(); //游標位置 return; } try { weight = float.Parse(WeightTextBox.Text); } catch { BmiStatusLabel.Text = "請輸入體重!"; BmiStatusLabel.ForeColor = Color.Blue; WeightTextBox.Text = ""; //TextBox清空 WeightTextBox.Focus(); //游標位置 return; } bmi = weight / ((height / 100.0f) * (height / 100.0f)); if (bmi > 24 || bmi < 18) { BmiStatusLabel.Text = "BMI = " + bmi.ToString("##.##") + ",BMI異常,請注意健康"; BmiStatusLabel.ForeColor = Color.Red; } else { BmiStatusLabel.Text = "BMI = " + bmi.ToString("##.##") + ",BMI正常"; BmiStatusLabel.ForeColor = Color.Green; } }
private void CalculateButton_Click(object sender, EventArgs e) { if (HeightTextBox == null || HeightTextBox.Text == "") { BMIRichTextBox.Clear(); HeightTextBox.AppendText("Text cannot be null"); } if (WeightTextBox == null || WeightTextBox.Text == "") { BMIRichTextBox.Clear(); WeightTextBox.AppendText("Text cannot be null"); } else { BMIRichTextBox.Clear(); Calculate(); } }
private void CalculateBMIButton_Click(object sender, EventArgs e) { // Declare local variables to store input and calculated values double height = 0; double weight = 0; double bmi = 0; // Determine height is not a numeric value if (!double.TryParse(HeightTextBox.Text, out height)) { MessageBox.Show("Height must be a numeric value", "Invalid Input!"); HeightTextBox.Focus(); } // Determine weight is not a numeric value else if (!double.TryParse(WeightTextBox.Text, out weight)) { MessageBox.Show("Weight must be a numeric value", "Invalid Input!"); WeightTextBox.Focus(); } else // If both inputs are OK then calculate the BMI { // Determine which measurement units has selected if (ImperialRadioButton.Checked) { // If imperial unit has selected bmi = (weight * 703) / (height * height); } else { // If metric unit has selected bmi = weight / (height * height); } // Display calculated BMI BmiTextBox.Text = bmi.ToString("N2"); // Call DisplayResult() method to display BMI status and update progress bar DisplayResult(bmi); } }
/// <summary> /// HeightTextBox_Click and WeightTextBox_Click are the click event handlers for the text boxes which allows /// to select the text in the text box so the user don't have to use the backspace or delete option /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HeightTextBox_Click(object sender, EventArgs e) { HeightTextBox.SelectAll(); }
private void HeightTextBox_TextChanged(object sender, TextChangedEventArgs e) { HeightTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource(); }
private void CalculateBMI_Click(object sender, EventArgs e) { //initialize variables double result; double height; double weight; try { if (HeightTextBox.Text == "" || WeightTextBox.Text == "") { MessageBox.Show("Fields can not be empty, please fill them out"); if ((HeightTextBox.Text == "") || (HeightTextBox.Text == "" && WeightTextBox.Text == "")) { HeightTextBox.Focus(); } else { WeightTextBox.Focus(); } } try { height = Convert.ToDouble(HeightTextBox.Text); weight = Convert.ToDouble(WeightTextBox.Text); } catch (Exception) { MessageBox.Show("Please type numbers"); HeightTextBox.Clear(); WeightTextBox.Clear(); HeightTextBox.Focus(); } height = Convert.ToDouble(HeightTextBox.Text); weight = Convert.ToDouble(WeightTextBox.Text); if (imperialRadBtn.Checked == true) { result = ((weight * 703)) / ((height * height)); ResultTextBox.Text = Convert.ToString(result); if (result < 18.5) { ResultInfoTextBox.Text = Convert.ToString("Underweight"); } if ((result > 18.5) && (result < 24.9)) { ResultInfoTextBox.Text = Convert.ToString("Normal"); } if ((result > 25) && (result < 29.9)) { ResultInfoTextBox.Text = Convert.ToString("Overweight"); } if (result > 30) { ResultInfoTextBox.Text = Convert.ToString("Obese"); } } else if (metricRadBnt.Checked == true) { result = (weight / (height * height)); ResultTextBox.Text = Convert.ToString(result); if (result < 18.5) { ResultInfoTextBox.Text = Convert.ToString("Underweight"); } if ((result > 18.5) && (result < 24.9)) { ResultInfoTextBox.Text = Convert.ToString("Normal"); } if ((result > 25) && (result < 29.9)) { ResultInfoTextBox.Text = Convert.ToString("Overweight"); } if (result > 30) { ResultInfoTextBox.Text = Convert.ToString("Obese"); } } } catch (Exception) { MessageBox.Show("Press OK"); } }
//Submit button private void button1_Click(object sender, EventArgs e) { //First Name validiation and parsing string firstName = firstNameTextBox.Text; if (firstName.Length < 1 || firstName.Length > 32) { MessageBox.Show("First Name must be between 1-32 characters long"); return; } if (!Regex.IsMatch(firstName, @"^[a-zA-Z]+$")) { MessageBox.Show("First Name can only contain alphabetic characters"); return; } //Last Name validiation and parsing string lastName = lastNameTextBox.Text; if (lastName.Length < 1 || lastName.Length > 32) { MessageBox.Show("Last Name must be between 1-32 characters long"); return; } if (!Regex.IsMatch(lastName, @"^[a-zA-Z]+$")) { MessageBox.Show("Last Name can only contain alphabetic characters"); return; } //BattleRosterNumber validation and parsing string battleRosterNumber = battleRosterNumberTextBox.Text; if (!Regex.IsMatch(battleRosterNumber, @"^[A-Z][A-Z][0-9][0-9][0-9][0-9]$")) { MessageBox.Show("Battle Roster Number must first 2 intials of last name in upercase and last 4 SSN numbers. (ie. AB1234)"); return; } //Height validation and parsing float height; if (float.TryParse(HeightTextBox.Text, out height)) { if (height < 1.0 || height > 12.0) { MessageBox.Show("Enter a valid height"); return; } } else { MessageBox.Show("Enter a valid height"); return; } //Weight validation and parsing float weight; if (float.TryParse(WeightTextBox.Text, out weight)) { if (weight < 1.0 || weight > 600.0) { MessageBox.Show("Enter a valid weight"); return; } } else { MessageBox.Show("Enter a valid weight"); return; } //Age validation and parsing int age; if (int.TryParse(AgeTextBox.Text, out age)) { if (age < 17 || age > 110) { MessageBox.Show("Enter a valid age"); return; } } else { MessageBox.Show("Enter a valid age"); return; } //Heat Casualty selection bool heatCat = true; if (HeatCatNoRadioButton.Checked) { heatCat = false; } if (HeatCatYesRadioButton.Checked) { heatCat = true; } //Male Female selection char sex = 'M'; if (SexMaleRadioButton.Checked) { sex = 'M'; } if (SexFemaleRadioButton.Checked) { sex = 'F'; } //Add data to the xmloader class Solider solider = new Solider(firstName, lastName, battleRosterNumber, heatCat, height, weight, sex); Program.xLoader.AddSoliderToRoster(solider); //Clear all data from textboxs and reset radio buttons firstNameTextBox.Clear(); lastNameTextBox.Clear(); battleRosterNumberTextBox.Clear(); HeightTextBox.Clear(); WeightTextBox.Clear(); AgeTextBox.Clear(); HeatCatYesRadioButton.Checked = true; SexMaleRadioButton.Checked = true; //Hide Form and return to previous form menuButtonPressed = true; FormProvider.AddSolider.Close(); FormProvider.RosterDisplay.Show(); }
private void HeightTextBox_Enter(object sender, EventArgs e) { HeightTextBox.Clear(); }
//Calculate Button+++++++++++++++++++++++++++++++++++++++++++++ private void CalculateButton_Click(object sender, EventArgs e) { //declear local variables double height, weight, chest, bMI, cMI; try { //convert to numbers height = Convert.ToDouble(HeightTextBox.Text); weight = Convert.ToDouble(WeightTextBox.Text); //each textbox can't be empty if (HeightTextBox.Text == "" || WeightTextBox.Text == "") { MessageBox.Show("All the text box can't be empty!"); } //height or weight can't be negative or zero else if (height <= 0 || weight <= 0) { MessageBox.Show("Height or Weight can't be negative or zero!"); HeightTextBox.Focus(); HeightTextBox.SelectAll(); } else if (height > 0 || weight > 0) { //when calculated, desable inputed textboxes HeightTextBox.Enabled = false; WeightTextBox.Enabled = false; ChestTextBox.Enabled = false; //calculates the BMI for Male if (MaleRadioButton.Checked == true) { //algorithm bMI = weight / ((height / 100) * (height / 100)); BMITextBox.Text = Convert.ToString(bMI); //detarmine BMI if (bMI < 18.5) { PictureBox.Image = this._imageArrayM[0]; MessageBox.Show("Underweight < 18.5"); } else if (bMI >= 18.5 && bMI <= 24.9) { PictureBox.Image = this._imageArrayM[1]; MessageBox.Show("Normal weight = 18.5~24.9 "); } else if (bMI > 25 && bMI <= 29.9) { PictureBox.Image = this._imageArrayM[2]; MessageBox.Show("Overweight = 25~29.9"); } else if (bMI >= 30) { PictureBox.Image = this._imageArrayM[3]; MessageBox.Show("Obesity >= 30"); } } //calculates the BMI for Female else if (FemaleRadioButton.Checked == true) { //algorithm bMI = weight / ((height / 100) * (height / 100)); BMITextBox.Text = Convert.ToString(bMI); //claculate cMI chest = Convert.ToDouble(ChestTextBox.Text); cMI = chest / height; CMITextBox.Text = Convert.ToString(cMI); //detarmine BMI if (bMI < 18.5) { PictureBox.Image = this._imageArrayFe[0]; MessageBox.Show("Underweight < 18.5"); } else if (bMI >= 18.5 && bMI <= 24.9) { PictureBox.Image = this._imageArrayFe[1]; MessageBox.Show("Normal weight = 18.5~24.9 "); } else if (bMI > 25 && bMI <= 29.9) { PictureBox.Image = this._imageArrayFe[2]; MessageBox.Show("Overweight = 25~29.9"); } else if (bMI >= 30) { PictureBox.Image = this._imageArrayFe[3]; MessageBox.Show("Obesity >= 30"); } } } } catch (Exception) { MessageBox.Show("You must fill all the forms, and Height, Weight can't be less or equal to 0"); HeightTextBox.Focus(); HeightTextBox.SelectAll(); } }
/** * <summary> * This eventhandler calculate the BMI and display on the textboxes * </summary> * * @method CalculateButton_Click * @param {object} sender * @param {EventArgs} e */ private void CalculateButton_Click(object sender, EventArgs e) { // local variables double height = 0, weight = 0, BMI; try { height = Convert.ToDouble(HeightTextBox.Text); weight = Convert.ToDouble(WeightTextBox.Text); } catch (FormatException) { MessageBox.Show("Fill out the forms"); } if (HeightTextBox.Text == "" || WeightTextBox.Text == "") { HeightTextBox.Focus(); HeightTextBox.SelectAll(); WeightTextBox.Focus(); WeightTextBox.SelectAll(); } else if (height < 0 || weight < 0) { MessageBox.Show("Please provide positive values"); } else if (height > 0 && weight > 0) { // in case the input is in imperial if (ImperialButton.Checked == true) { // calculate BMI in imperial BMI = (weight * 703) / (height * height); // condition to set progress bar value if (((BMI / 30) * 100) > 100) { BMIProgressBar.Value = 100; } else { BMIProgressBar.Value = ((int)((BMI / 30) * 100)); } BMIResultBox.Text = string.Format("{0:f1}", BMI); BMIResultBox.BackColor = Color.LightSalmon; BMIScaleBox.BackColor = Color.LightSalmon; // determine the BMI if (BMI < 18.5) { this.BMIScaleBox.Text = ("Underweight"); BMIProgressBar.ForeColor = Color.Yellow; } else if (BMI >= 18.5 && BMI <= 24.9) { this.BMIScaleBox.Text = ("Normal"); BMIProgressBar.ForeColor = Color.Green; } else if (BMI >= 25 && BMI <= 29.9) { this.BMIScaleBox.Text = ("Overweight"); BMIProgressBar.ForeColor = Color.DarkGreen; } else if (BMI >= 30) { this.BMIScaleBox.Text = ("Obese"); BMIProgressBar.ForeColor = Color.Red; } } // in case the input is in metric units else if (MetricUnitsButton.Checked == true) { // calculate BMI in metric units BMI = weight / ((height * height) / 10000); // condition to set progress bar value if (((BMI / 30) * 100) > 100) { BMIProgressBar.Value = 100; } else { BMIProgressBar.Value = ((int)((BMI / 30) * 100)); } BMIResultBox.Text = string.Format("{0:f1}", BMI); BMIResultBox.BackColor = Color.LightSalmon; BMIScaleBox.BackColor = Color.LightSalmon; BMIProgressBar.Maximum = 100; // determine the BMI if (BMI < 18.5) { this.BMIScaleBox.Text = ("Underweight"); BMIProgressBar.ForeColor = Color.Yellow; } else if (BMI >= 18.5 && BMI <= 24.9) { this.BMIScaleBox.Text = ("Normal"); BMIProgressBar.ForeColor = Color.Green; } else if (BMI >= 25 && BMI <= 29.9) { this.BMIScaleBox.Text = ("Overweight"); BMIProgressBar.ForeColor = Color.DarkGreen; } else if (BMI >= 30) { this.BMIScaleBox.Text = ("Obese"); BMIProgressBar.ForeColor = Color.Red; } } } }
/** * <summary> * This eventhandler calculate the BMI and display on the textboxes * </summary> * * @method CalculateButton_Click * @param {object} sender * @param {EventArgs} e */ //Calculate Button+++++++++++++++++++++++++++++++++++++++++++++ private void CalculateButton_Click(object sender, EventArgs e) { //declear local variables double height, weight, bMI; try { //convert to numbers height = Convert.ToDouble(HeightTextBox.Text); weight = Convert.ToDouble(WeightTextBox.Text); //each textbox can't be empty if (HeightTextBox.Text == "" || WeightTextBox.Text == "") { MessageBox.Show("All the text box can't be empty!"); } //height or weight can't be negative or zero else if (height <= 0 || weight <= 0) { MessageBox.Show("Height or Weight can't be negative or zero!"); HeightTextBox.Focus(); HeightTextBox.SelectAll(); } else if (height > 0 || weight > 0) { //when calculated, desable inputed textboxes HeightTextBox.Enabled = false; WeightTextBox.Enabled = false; //calculates the BMI Metric if (MetricRadioButton.Checked == true) { //algorithm bMI = weight / ((height) * (height)); BMITextBox.Text = Convert.ToString(bMI); // condition to set progress bar value if (((bMI / 30) * 100) > 100) { progressBar1.Value = 100; } else { progressBar1.Value = ((int)((bMI / 30) * 100)); } //determine BMI if (bMI < 18.5) { MessageBox.Show("Underweight < 18.5"); progressBar1.ForeColor = Color.Yellow; } else if (bMI >= 18.5 && bMI <= 24.9) { MessageBox.Show("Normal weight = 18.5~24.9 "); progressBar1.ForeColor = Color.Green; } else if (bMI > 25 && bMI <= 29.9) { MessageBox.Show("Overweight = 25~29.9"); progressBar1.ForeColor = Color.DarkGreen; } else if (bMI >= 30) { MessageBox.Show("Obesity >= 30"); progressBar1.ForeColor = Color.Red; } } //calculates the BMI for Imperial else if (ImperialRadioButton.Checked == true) { //algorithm bMI = (weight * 4.88) / ((height) * (height)); BMITextBox.Text = Convert.ToString(bMI); // condition to set progress bar value if (((bMI / 30) * 100) > 100) { progressBar1.Value = 100; } else { progressBar1.Value = ((int)((bMI / 30) * 100)); } //detarmine BMI if (bMI < 18.5) { MessageBox.Show("Underweight < 18.5"); progressBar1.ForeColor = Color.Yellow; } else if (bMI >= 18.5 && bMI <= 24.9) { MessageBox.Show("Normal weight = 18.5~24.9 "); progressBar1.ForeColor = Color.Green; } else if (bMI > 25 && bMI <= 29.9) { MessageBox.Show("Overweight = 25~29.9"); progressBar1.ForeColor = Color.DarkGreen; } else if (bMI >= 30) { MessageBox.Show("Obesity >= 30"); progressBar1.ForeColor = Color.Red; } } } } catch (Exception) { MessageBox.Show("You must fill all the forms, and Height, Weight can't be less or equal to 0"); HeightTextBox.Focus(); HeightTextBox.SelectAll(); } }