public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SecondForm = new ResultOfBMICalculator(); FirstForm = new BMICalculator(); SplashHome = new SplashHomeScreen(); Application.Run(SplashHome); }
// PRIVATE METHOD++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /* *<summary> If user Clicks Calculate BMI, This Event happens * <summary> * @method SubmitButton_Click * @property {void} */ private void SubmitButton_Click(object sender, EventArgs e) { //Create instance of ResultOfBMICalculator ResultOfBMICalculator SecondForm = new ResultOfBMICalculator(); //Create ProgressBar instance and assign to ProgressBar Which is in ResultOfBMICalculator Form ProgressBar Progress = SecondForm.ResultProcessingBar; //Height and Weight label is false till user choose Metric or Imperial HeightLabel2.Visible = false; WeightLabel2.Visible = false; // set try and catch to check if DivideByZeroException happends or not try { if (ActiveError == false)// if DivideByZeroException does not happen, this Event continues { if (ImperialRadioButton.Checked) { BMIResult = (Convert.ToDouble(WeighttextBox.Text) * 703) / (Convert.ToDouble(HeighttextBox.Text) * Convert.ToDouble(HeighttextBox.Text)); } else if (MetricRadioButton.Checked) { BMIResult = Convert.ToDouble(WeighttextBox.Text) / (Convert.ToDouble(HeighttextBox.Text) * Convert.ToDouble(HeighttextBox.Text)); } }//close ActiveError } catch (DivideByZeroException error) { Console.WriteLine(error.Message); } if (BMIResult < 18.5) { SecondForm.BMILevelLabel.Text = "Under Weight"; SecondForm.ForeColor = System.Drawing.Color.Aqua; } else if (BMIResult >= 18.5 && BMIResult <= 24.9) { SecondForm.BMILevelLabel.Text = "Normal"; SecondForm.ForeColor = System.Drawing.Color.Blue; } else if (BMIResult >= 25.0 && BMIResult <= 29.9) { SecondForm.BMILevelLabel.Text = "Over Weight"; SecondForm.ForeColor = System.Drawing.Color.Yellow; } else if (BMIResult >= 30) { SecondForm.BMILevelLabel.Text = "Obese"; SecondForm.ForeColor = System.Drawing.Color.Red; } int ResultForBar = (int)Program.FirstForm.BMIResult; Progress.Maximum = 100; Progress.Minimum = 0; switch (SecondForm.BMILevelLabel.Text) { case "Under Weight": Progress.Value = 25; Progress.BackColor = Color.Aqua; Progress.ForeColor = Color.Aqua; ProgressBarClass.SetState(Progress,1); break; case "Normal": Progress.Value = 50; Progress.BackColor = Color.Blue; Progress.ForeColor = Color.Blue; ProgressBarClass.SetState(Progress, 1); break; case "Over Weight": Progress.Value = 75; Progress.BackColor = Color.Yellow; Progress.ForeColor = Color.Yellow; ProgressBarClass.SetState(Progress, 3); break; case "Obese": Progress.Value = 100; Progress.BackColor = Color.Red; Progress.ForeColor = Color.Red; ProgressBarClass.SetState(Progress, 2); break; } //ResultOfBMICalculator's label shows BMI Result SecondForm.BMIResultLabel.Text = Convert.ToString(BMIResult); //ResultOfBMICalculator shows SecondForm.Show(); }