Beispiel #1
0
        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("#.##")));
        }
Beispiel #2
0
        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>
 /// 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();
 }
Beispiel #4
0
        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();
     }
 }
Beispiel #6
0
        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;
            }
        }
Beispiel #7
0
        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);
            }
        }
        //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
         */

        //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();
            }
        }
        /**
         * <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;
                    }
                }
            }
        }
Beispiel #11
0
        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");
            }
        }