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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started