我不斷收到以下錯誤消息在void KeyPress(object sender, KeyPressEventArgs e)
使用new關鍵字:按鍵時顯示警告,如果隱藏之意
警告「SpeedyRent.Form2.KeyPress(對象, System.Windows.Forms.KeyPressEventArgs)」隱藏繼承成員 'System.Windows.Forms.Control.KeyPress'。如果想要隱藏 ,請使用新關鍵字。
這是我到目前爲止的代碼:
void KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
有以下3個引用:
this.totalTxt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.KeyPress);
this.remainTxt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.KeyPress);
this.paidTxt.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.KeyPress);
是什麼原因造成的呢?
在這種情況下不是一種方法,而是一個事件。 –