0

I have this line of code that should convert a label and a textbox to int32 and then subtract them with eachother...

retur = Convert.ToInt32(pengarTxtbox.Text) - Convert.ToInt32(kostarLbl.Text);

retur is a int aswell.

This line gives me the error: Input string was not in a correct format. (I've never recived this error before)

WHY?! Am I missing something?

4

2 回答 2

4

You need to use the Text property to get the content of the Textbox and Label.

Try This:

retur = Convert.ToInt32(pengarTxtbox.Text) - Convert.ToInt32(kostarLbl.Text);
于 2014-05-23T06:41:27.367 回答
2

没有传递stringConvert.ToInt32(string value)而是传递控件本身,即TextBoxLabel. 您必须使用Text属性来获取Textboxand中的文本Label

retur = Convert.ToInt32(pengarTxtbox.Text) - Convert.ToInt32(kostarLbl.Text);
于 2014-05-23T06:41:40.707 回答