c# - 方法签名与文本框事件处理程序不匹配

标签 c# winforms events textbox

当我使用 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/

相关文章:

c# - 脚本在 UWP 的 WebView 中不起作用

c# 将多个词典合并为一个

c# - 方法运行时无法单击按钮

javascript - 当用户离开我的 Javascript/AngularJS 网站时,如何提示模式?

events - 处理 ViewModel 中的 TextBox 事件,例如 Text_changed

c# - 如何连续制作两个标签?第二个标签正确显示新行?

c# - Mono 和 Gtk 中的全局热键#

c# - 如何通过正则表达式识别文本中的段落?

c# - Winforms DataBinding 与 PropertyChanged 事件排序问题

c# - 在 FormClosing 事件中关闭应用程序