其實這個問題是由於「&」有特殊的意義-就是能夠做爲快捷鍵
- 第一種:Alt + *(按鈕快捷鍵)
-
- 在你們給button、label、menuStrip等控件設置Text屬性時在名字後邊加&鍵名就能夠了,好比button1.text= "肯定(&O)"。就會有快捷鍵了,這時候按Alt+O就能夠執行按鈕單擊事件。(文本顯示的是」肯定(0)「);
-
-
- 第二種:Ctrl+*及其餘組合鍵
- private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F&&e.Control)
{
e.Handled = true;
this.button1.Click += new EventHandler(button1_Click);
}
}
- 當使用Ctrl + *快捷鍵時,對於焦點在可寫的控件(如TextBox)上時,可能會將* 鍵值同時輸入,則須要加另外一句話將Handled設置爲true,以取消 KeyPress 事件。
- 來自:http://blog.csdn.net/gaofang2009/article/details/5172456