I have a program that calculates the area of a open field. I would like to understand how can I use the TryParse method to add two calculated values into a single text box called btnCalculate
Radiobutton when clicked, enables two textboxes E1 so that the user and input the values. These two textboxes are bounded in a groupbox.
I am wondering how can I add these two areas when button is clicked, one outside of the grpbox and the other within the grpbox using the TryParse method. Is it possible?
Thanks in advance.
For example:
private void btnCalculate_Click(object sender, EventArgs e)
{
double width, length;
bool status1 = double.TryParse(this.txbxWidth.Text, out width);
bool status2 = double.TryParse(this.txbxLength.Text, out length);
txbxArea.Text = string.Format("{0:f}", width * length);
if (rdb1.Checked)
{
double e1width, e1length;
bool status1 = double.TryParse(this.txbxE1width.Text, out e1width);
bool status2 = double.TryParse(this.txbxE1length.Text, out e1length);
txbxArea.Text = string.Format("{0:f}", e1width * e1length);
}

TryParse has nothing to do with the addition, etc. It is just for parsing the values.
You can add two areas as follows:
private void btnCalculate_Click(object sender, EventArgs e)
{
double width, length;
bool status1 = double.TryParse(this.txbxWidth.Text, out width);
bool status2 = double.TryParse(this.txbxLength.Text, out length);
txbxArea.Text = string.Format("{0:f}", width * length);
if (rdb1.Checked)
{
double e1width, e1length;
bool status1 = double.TryParse(this.txbxE1width.Text, out e1width);
bool status2 = double.TryParse(this.txbxE1length.Text, out e1length);
txbxArea.Text = string.Format("{0:f}", (width * length) + (e1width * e1length));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With