C# '无过载;textBox1_TextChanged';匹配委托';System.EventHandler';
大家好。这是我的第一个程序,在5分钟内我有一个错误。我今天才开始使用C#,所以我知道我真的应该四处看看,但我不认为我所做的有什么问题 我的程序是一个生成器 取决于用户在所有文本框中选择或键入的内容取决于生成代码的外观 我有两个文本框,分别名为:C# '无过载;textBox1_TextChanged';匹配委托';System.EventHandler';,c#,C#,大家好。这是我的第一个程序,在5分钟内我有一个错误。我今天才开始使用C#,所以我知道我真的应该四处看看,但我不认为我所做的有什么问题 我的程序是一个生成器 取决于用户在所有文本框中选择或键入的内容取决于生成代码的外观 我有两个文本框,分别名为:textBox1,和GeneratedCode 当我按下checkBox1时,它允许使用textbox1 当我按下按钮时,它创建了一个字符串“Testing”(这是为了确保我做对了) 当我按F5测试我的构建时,它返回了以下错误: No overload f
textBox1
,和GeneratedCode
当我按下checkBox1
时,它允许使用textbox1
当我按下按钮时,它创建了一个字符串“Testing”(这是为了确保我做对了)
当我按F5测试我的构建时,它返回了以下错误:
No overload for 'textBox1_TextChanged' matches delegate 'System.EventHandler'
我不知道这是什么意思
这是我的密码:
public void checkBox1_CheckedChanged(object sender, EventArgs e)
{
switch (checkBox1.Checked)
{
case true:
{
textBox1.Enabled = true;
break;
}
case false:
{
textBox1.Enabled = false;
break;
}
}
}
private void textBox1_TextChanged()
{
}
public void button1_Click(object sender, EventArgs e)
{
GenerateBox.Text += "Testing";
}
private void GenerateBox_Generated(object sender, EventArgs e)
{
}
这是C++中的form1.designer:
//
// textBox1
//
this.textBox1.Enabled = false;
this.textBox1.Location = new System.Drawing.Point(127, 3);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(336, 20);
this.textBox1.TabIndex = 1;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); //Error
//
// GenerateBox
//
this.GenerateBox.Enabled = false;
this.GenerateBox.Location = new System.Drawing.Point(84, 6);
this.GenerateBox.MaxLength = 1000000;
this.GenerateBox.Multiline = true;
this.GenerateBox.Name = "GenerateBox";
this.GenerateBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.GenerateBox.Size = new System.Drawing.Size(382, 280);
this.GenerateBox.TabIndex = 1;
this.GenerateBox.TextChanged += new System.EventHandler(this.GenerateBox_Generated);
您的
textbox1\u TextChanged
方法与System.EventHandler
委托的预期不匹配。应该是
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
您的
textbox1\u TextChanged
方法与System.EventHandler
委托的预期不匹配。应该是
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
函数textbox1_textChanged应该有两个参数,如下所示,在本例中EventHandler可以接受
textBox1_TextChanged(object sender, EventArgs e)
函数textbox1_textChanged应该有两个参数,如下所示,在本例中EventHandler可以接受
textBox1_TextChanged(object sender, EventArgs e)
编译器会准确地告诉您出了什么问题,您没有名为
textBox1\u TextChanged
的EventHandler
将textBox1\u TextChanged
方法更改为:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//Why are you handling this event if you aren't actually doing anything here???
}
关于这个问题的其余部分,请参考我的代码示例的注释部分
如果您不想为此事件添加处理程序,只需从设计器代码中删除以下内容:
textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
编译器会准确地告诉您出了什么问题,您没有名为
textBox1\u TextChanged
的EventHandler
将textBox1\u TextChanged
方法更改为:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//Why are you handling this event if you aren't actually doing anything here???
}
关于这个问题的其余部分,请参考我的代码示例的注释部分
如果您不想为此事件添加处理程序,只需从设计器代码中删除以下内容:
textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
不客气:)别忘了点击我的答案或“关系”答案左边的复选标记(你可能需要等待几分钟)将线程标记为已回答。不客气:)别忘了点击我的答案或“关系”答案左边的复选标记将线程标记为已回答(你可能需要等待几分钟))是的,请标明“关系”或“键盘”作为答案。他们是正确的,第一个=)同样的问题:受保护的无效文本框1_TextChanged(对象发送者,System.Windows.Forms.KeyEventArgs e){}它将做一些我现在正在做的事情好交易=)是的,请标记关系或键盘P作为答案。它们是正确的,并且第一个=)的问题相同:受保护的void TextBox1_TextChanged(对象发送者,System.Windows.Forms.KeyEventArgs e){}