C#为控件添加快捷键的问题
假设我在form1上有个按钮send,send的click事件为 send_click,如何为send添加快捷键ctrl + S?
我的做法是这样:(问题在中间的注释行)
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (keyData == (Keys.Control | Keys.S))
{
//..这里该如何与send_click联系起来
}
return base.ProcessCmdKey(ref msg, keyData);
}
或者有另外方法请告诉我,谢谢
------解决方案--------------------send_click(this, EventArgs.Empty);
------解决方案--------------------建议将Save操作放入独立函数,在有send_click和ProcessCmdKey调用
public void Save()
{
...
}
send_click (object sender, eventArgs e)
{
Save();
}
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (keyData == (Keys.Control | Keys.S))
{
Save();
}
return base.ProcessCmdKey(ref msg, keyData);
}