String 类型为'的值;字符串';无法转换为System.Windows.Forms.Label

String 类型为'的值;字符串';无法转换为System.Windows.Forms.Label,string,vb.net,String,Vb.net,我有点傻。当我试图构建我的解决方案时,我遇到了一个错误,我不知道该怎么做来修复它 'Calculate and display cost estimate decCostEstimate = decFeet * decCostPerFoot **lblCostEstimate = decCostEstimate.ToString("C")** 我不知道该怎么办。请帮助我。您想设置标签的文本属性,而不是标签本身 lblCostEs

我有点傻。当我试图构建我的解决方案时,我遇到了一个错误,我不知道该怎么做来修复它

 'Calculate and display cost estimate
                decCostEstimate = decFeet * decCostPerFoot
                **lblCostEstimate = decCostEstimate.ToString("C")**

我不知道该怎么办。请帮助我。

您想设置标签的文本属性,而不是标签本身

lblCostEstimate.Text = decCostEstimate.ToString("C")

代码试图为Label类型的对象分配字符串值,从而导致错误。

您想设置标签的文本属性,而不是标签本身

lblCostEstimate.Text = decCostEstimate.ToString("C")

代码试图将字符串值分配给Label类型的对象,从而导致错误。

标签是来自Label类型的对象。 无法将类型
int
string
等中的对象写入标签对象

要使标签显示结果,只需将结果放入标签的文本属性中:


lblCostEstimate.Text=decCostEstimate.ToString(“C”)
标签是类型
标签中的对象。
无法将类型
int
string
等中的对象写入标签对象

要使标签显示结果,只需将结果放入标签的文本属性中:


lblCostEstimate.Text=decCostEstimate.ToString(“C”)

如果您使用,Visual Studio会在您尝试构建解决方案之前告诉您有问题。您可以在“工具”菜单->选项->项目和解决方案->VB默认值中找到此设置。这将使您在运行时避免出现错误。如果您使用,则Visual Studio将在您尝试构建解决方案之前告诉您有问题。您可以在“工具”菜单->选项->项目和解决方案->VB默认值中找到此设置。这将使您在运行时避免出现bug。