I am writing a program in Visual Studio 2015 using Windows Forms . There are 4 pieces of textBox in which you need to enter numeric values ​​and label10 , where the result of the calculation is displayed after pressing the button1 . Here is the code snippet:

 private void button1_Click(object sender, EventArgs e) { label10.Text = Convert.ToString(Convert.ToDouble(textBox1) * Convert.ToDouble(textBox2) * Convert.ToDouble(textBox3) * Convert.ToDouble(textBox4) * 0.00000786); } 

I start, I enter 4 values, I press the button and the error pops up:

Exception thrown: 'System.InvalidCastException' in mscorlib.dll

Additional information: System.Windows.Forms.TextBox 'to type' System.IConvertible '.

In this case, the editor highlights for some reason the semicolon at the end of the line. I changed the conversion to both Float and different Int16 , Int32 - there is no result.

Help correct the error.

  • one
    textBox1.Text and so on - Igor
  • Thanks, I'm not careful. - Evgeny Mitin
  • You can use NumericUpDown instead of TextBox . It allows you to enter only numbers (both integers and real). - Alexander Petrov

0