我在检查文本框并确保其中只有整数时遇到问题。
到目前为止,我能够确认文本框中有文本,但检查它们是否是整数不起作用。这是我到目前为止有效的代码。
if (textBox1.Text.Length == 0)
{
errorProvider1.SetError(textBox1, "need Cost of Disks");
return;
}
if (textBox2.Text.Length == 0)
{
errorProvider2.SetError(textBox2, "need Total disks in package");
return;
}
if (textBox3.Text.Length == 0)
{
errorProvider3.SetError(textBox3, "need the Gigabyte per disk");
return;
}
try
{
Double[] myValues = new Double[3];
myValues[0] = Double.Parse(textBox1.Text);
myValues[1] = Double.Parse(textBox2.Text);
myValues[2] = Double.Parse(textBox3.Text);
Double ppd = myValues[0] / myValues[1] / myValues[2];
ppd = Math.Round(ppd, 3, MidpointRounding.AwayFromZero);
label4.Text = ppd.ToString();
}
catch (FormatException)
{
//errorProvider1.SetError(label4, "testing1");
//errorProvider2.SetError(label4, "testing2");
//errorProvider3.SetError(label4, "testing3");
return;
}