vb.net 如何在visual basic的文本框中显示整数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40454533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I display an integer in a textbox in visual basic
提问by tedd felt
I have searched DreamInCode and even this site but I have not found an answer.
I am very new to programming and I guess this is just so simple I should know, but I don't. In Visual Basic how do I make a TextBoxdisplay an Integer. For example:
我已经搜索了 DreamInCode 甚至这个网站,但我还没有找到答案。我对编程很陌生,我想这很简单,我应该知道,但我不知道。在 Visual Basic 中,如何使TextBox显示为Integer. 例如:
Private Sub timer1(sender As System.Object, e As System.EventArgs)
Dim GDP As Integer
GDP = 125000
PictureBox1 = GDP
End Sub
It gives me this error
它给了我这个错误
Value of type 'integer' cannot be converted to picture box
“整数”类型的值无法转换为图片框
I have seen answers to similar problems in c# and in more complex cases but none for mine can anyone help?
我已经在 c# 和更复杂的情况下看到了类似问题的答案,但没有人能帮助我吗?
回答by Maksim Sestic
You are doing it wrong. TextBoxrepresents a control that displays plain text, while PictureBoxcontrol displays an image (raster) object. In this particular case you need TextBoxcontrol to display your GDPvalue, and you need to use it like this:
你做错了。TextBox表示一个显示纯文本的PictureBox控件,而控件显示一个图像(光栅)对象。在这种特殊情况下,您需要TextBox控制来显示您的GDP值,您需要像这样使用它:
TextBox1.Text = GDP.ToString
...since you need your integer GDPvalue converted to string beforehand.
...因为您需要GDP事先将整数值转换为字符串。

