我想構建一個有一個按鈕的程序,並且每次單擊該按鈕時,它都會移動按鈕並添加到樂譜中。但是,我試圖禁用Enter鍵,或者按下時禁止該命令。以下是我迄今爲止沒有爲'insert_method_here'重載匹配委託'System.EventHandler'
private void button1_Click(object sender, EventArgs e, KeyEventArgs k)
{
if (k.KeyCode == Keys.Enter)
{
k.SuppressKeyPress = true;
}
score = score + 10;
timesClicked++;
int rand1 = RandomNumber(1, 400);
int rand2 = RandomNumber(1, 400);
button1.Location = new Point(rand1, rand2);
toolStripScore.Text = ("Your score is " + score);
toolStripClicks.Text = ("You've clicked the button{0} times " + timesClicked);
winCheck();
}
這是我加什麼來防止輸入鍵從去。
if (k.KeyCode == Keys.Enter) { k.SuppressKeyPress = true; }
但是它產生的錯誤......「爲‘的button1_Click’不超載匹配委託'System.EventHandler'「當單擊以顯示位置時,它將打開Form1.Designer的代碼並指向此行。 「this.button1.Click + = new System.EventHandler(this.button1_Click);」
任何幫助解決這個問題將不勝感激。
我試圖把兩者 私人無效Form1_KeyDown(對象發件人,發送KeyEventArgs E) 和 私人無效button1_KeyDown(對象發件人,發送KeyEventArgs E) 隨着程序和if語句沒有的事防止輸入鍵工作。 – Cistoran 2010-08-27 01:28:09
@Cistorian嘗試'MouseClick'事件,那麼應該忽略設計的輸入鍵 – max 2010-08-27 01:29:58
你是什麼意思試試MouseClick?用什麼來試試? – Cistoran 2010-08-27 01:33:30