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.
textBox1.Textand so on - IgorNumericUpDowninstead ofTextBox. It allows you to enter only numbers (both integers and real). - Alexander Petrov