FormatException 未处理:输入字符串的格式不正确
FormatException was unhandled: Input string was not in a correct format
我无法将两个文本框的值相乘。
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text))
{
textBox3.Text = (Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox2.Text)).ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox3.Text) && !string.IsNullOrEmpty(textBox4.Text))
{
textBox5.Text = (Convert.ToInt32(textBox3.Text) + Convert.ToInt32(textBox4.Text)).ToString();
}
}
这里有一些东西可以为您指明正确的方向...
private void button1_Click(object sender, EventArgs e)
{
float tbox1 = float.Parse(textBox1.Text);
float tbox2 = float.Parse(textBox2.Text);
float tbox12;
if (textBox1 != null && textBox2 != null)
{
tbox12 = tbox1 + tbox2;
textBox3.Text = tbox12.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
float tbox3 = float.Parse(textBox3.Text);
float tbox4 = float.Parse(textBox4.Text);
float tbox34;
if (textBox3 != null && textBox4 != null)
{
tbox34 = tbox3 + tbox4;
textBox5.Text = tbox34.ToString();
}
}
我无法将两个文本框的值相乘。
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text))
{
textBox3.Text = (Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox2.Text)).ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox3.Text) && !string.IsNullOrEmpty(textBox4.Text))
{
textBox5.Text = (Convert.ToInt32(textBox3.Text) + Convert.ToInt32(textBox4.Text)).ToString();
}
}
这里有一些东西可以为您指明正确的方向...
private void button1_Click(object sender, EventArgs e)
{
float tbox1 = float.Parse(textBox1.Text);
float tbox2 = float.Parse(textBox2.Text);
float tbox12;
if (textBox1 != null && textBox2 != null)
{
tbox12 = tbox1 + tbox2;
textBox3.Text = tbox12.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
float tbox3 = float.Parse(textBox3.Text);
float tbox4 = float.Parse(textBox4.Text);
float tbox34;
if (textBox3 != null && textBox4 != null)
{
tbox34 = tbox3 + tbox4;
textBox5.Text = tbox34.ToString();
}
}