当我使用 Char.IsNumber
时,它会在 form1.designer.cs
中产生一个错误。
No overload for "
textBox1_TextChanged
" matches delegate 'System.EventHandler
'
private void textBox1_TextChanged(object sender, KeyPressEventArgs e)
{
if (char.IsNumber(e.KeyChar))
{
textBox1.Text = e.KeyChar.ToString();
}
else
{
MessageBox.Show("Char value");
}
}
///////////// Text Box ///////////////
this.textBox1.Location = new System.Drawing.Point(73, 57);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(177, 20);
this.textBox1.TabIndex = 0;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // error occurs on this line
最佳答案
将 KeyPressEventArgs
更改为 TextChangedEventArgs
(对于 WPF,对于 winforms 使用 EventArgs
)。该错误告诉您 TextChanged
事件的签名与您分配给它的方法不匹配。
关于c# - 方法签名与文本框事件处理程序不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19364230/