c# warn if text box is empty or contains a non-whole number
Posted
by
Jamaul Smith
on Stack Overflow
See other posts from Stack Overflow
or by Jamaul Smith
Published on 2012-10-05T21:35:16Z
Indexed on
2012/10/05
21:37 UTC
Read the original article
Hit count: 192
In my specific case, I need the value in propertyPriceTextBox to be numeric only, and a whole number. A value also has to be entered, and I can just Messagebox.Show() a warning and that's all I'd need to do.
This is what I have so far.
private void computeButton_Click(object sender, EventArgs e)
{
decimal propertyPrice;
if ((decimal.TryParse(propertyPriceTextBox.Text, out propertyPrice)))
decimal.Parse(propertyPriceTextBox.Text);
{
if (residentialRadioButton.Checked == true)
commisionLabel.Text = (residentialCom * propertyPrice).ToString("c");
if (commercialRadioButton.Checked == true)
commisionLabel.Text = (commercialCom * propertyPrice).ToString("c");
if (hillsRadioButton.Checked == true)
countySalesTaxTextBox.Text = ( hilssTax * propertyPrice).ToString("c");
if (pascoRadioButton.Checked == true)
countySalesTaxTextBox.Text = (pascoTax * propertyPrice).ToString("c");
if (polkRadioButton.Checked == true)
countySalesTaxTextBox.Text = (polkTax * propertyPrice).ToString("c");
decimal result;
result = (countySalesTaxTextBox.Text + stateSalesTaxTextBox.Text + propertyPriceTextBox.Text + comissionTextBox.Text).ToString("c");
}
else (.)
MessageBox.Show("Property Price must be a whole number.");
}
© Stack Overflow or respective owner