2013-10-14 27 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。你確定這是你想要的事件嗎?

相關問題