Question: I need code to display the Messagebox error to display. (c# windows form) Use a try-catch block to prevent the program from crashing if a

I need code to display the Messagebox error to display. (c# windows form)

Use a try-catch block to prevent the program from crashing if a nonnumeric value is entered. The try catch block must prevent the calculation from taking place; it should also prevent any output from being displayed. If nonnumeric data is entered into the text box and Calculate is clicked, then instead we should get an error message via a MessageBox asking us to enter a valid, numeric value.

Code So Far:

namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

private void textBox2_TextChanged(object sender, EventArgs e) {

}

private void label1_Click(object sender, EventArgs e) {

}

private void label2_Click(object sender, EventArgs e) {

}

private void label3_Click(object sender, EventArgs e) {

}

private void label4_Click(object sender, EventArgs e) {

}

private void btnCalculate_Click(object sender, EventArgs e) { double mealAmount, totalAmount, tipAmount, tax; mealAmount = Convert.ToDouble(foodCharge.Text); tipAmount = mealAmount * 0.15; tax = mealAmount * 0.07; totalAmount = mealAmount + tipAmount + tax; lblTax.Text = tax.ToString("C"); lblTip.Text = tipAmount.ToString("C"); lblTotalAmount.Text = totalAmount.ToString("C"); }

private void btnExit_Click(object sender, EventArgs e) { this.Close(); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!