2013-10-14 16 views
2

当我使用Char.IsNumber时,它在form1.designer.cs中创建一个错误。方法签名与文本框事件处理程序不匹配

无过载为 “textBox1_TextChanged” 匹配委托 '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 
+0

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.textchanged.aspx –

回答

2

变化KeyPressEventArgsTextChangedEventArgs(为WPF,为的WinForms使用EventArgs)。错误是告诉您TextChanged事件的签名与您分配给它的方法不匹配。

+0

我认为'TextChangedEventArgs'只在WPF中,这看起来像Windows窗体。 – Chris

0

你的处理程序TextChanged事件的签名不匹配,试试这个:

private void textBox1_TextChanged(object sender, EventArgs e) 

此外,当你这样做,你会发现,没有对TextChanged事件没有e.KeyChar。你确定这是你想要的事件吗?

相关问题