I am trying to use TryParse so that I can show a message box if anything other than a number is input into a text box on windows forms.
a() is a function I have created which will return the value of the text box text (users input). It works fine if I input a number into the text box that it is parsing from, however if it is anything other than a number, then it will show the message box (great), I'll close the message box but then it will show once more. I only want the message box to show once.
"TB_lengthA" is the name of the text box in my winform app.
public double a()
{
double a;
if (double.TryParse(TB_lengthA.Text, out a))
{
}
else
{
MessageBox.Show("Please type a number");
}
return a;
}
Aucun commentaire:
Enregistrer un commentaire