1. 程式人生 > 其它 >winform 鍵盤控制元件模組

winform 鍵盤控制元件模組

#region 設定鍵盤控制元件,讓鍵盤的回車也能觸發確定按鈕
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
//button1.Focus();
button1.PerformClick();
}
/*
// if it is a hotkey, return true; otherwise, return false
switch (keyData)
{
case Keys.Enter:
//焦點定位到控制元件button1上,即回車鍵上
button1.Focus();
//執行按鈕點選操作
button1.PerformClick();
return true;
case Keys.NumPad1:
button2.Focus();
button2.PerformClick();
return true;
//......
default:
break;
}
*/
return base.ProcessCmdKey(ref msg, keyData);
}
#endregion