无法将类型’string’隐式转换为’System.Windows.Forms.TextBox’

我不知道该怎么办,因为错误发生在Form1.Designer.cs ,因为我没有调试程序部分的经验。

 //Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(352, 246); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Generate Username"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.ResumeLayout(false); 

错误在this.Name =“Form1”;

我怀疑你已经创建了一个名为Name的控件,它与窗口的Name属性冲突。 只需将控件重命名为其他内容,它应该再次起作用。

错误必须来自其他地方,这里没有任何TextBox 。 该错误可能是由于将字符串分配给TextBox本身而不是将字符串分配给TextBox的Text属性引起的。

例:

 TextBox tb = new TextBox(); tb = "Default text"; 

这应该是:

 TextBox tb = new TextBox(); tb.Text = "Default text"; 

否则,您已创建一个名称如NameText的控件,在这种情况下,您必须将其重命名为NameTextBox或其他内容。