简体   繁体   中英

Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

I don't know what to do because the error is in the Form1.Designer.cs and because I have no experience in debugging that part of the program.

//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);

The error is on this.Name = "Form1";

I suspect you have created a control named Name , which conflicts with the Name property of the window. Just rename the control to something else and it should work again.

The error must come from somewhere else, there's nothing here with a TextBox . The error is probably caused by assigning a string to a TextBox itself instead of assigning a string to the Text property of the TextBox.

Example:

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

This should be:

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

Otherwise you have created a control with a name like Name or Text , in which case you'll have to rename it to NameTextBox or something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM