![](/img/trans.png)
[英]As if ALT doesn't get released - using shortcut keys / Alt+key combination
[英]Windows form hot keys using ALT+Key, if the same key combination with case change
我们创建了具有两个按钮“取消”和“清除”的Windows窗体。 我们将按钮文本设置为&Cancel和&clear,将快捷键组合设置为Alt + key 。 但是当我们按Alt + c时 ,仅适用于“取消”按钮。 而是为什么它不会在Windows窗体的这两个按钮之间切换,就像在VB6窗体中切换一样。 如果按下Alt + c,则需要在这两个按钮之间切换。 请建议需要设置任何表单属性或按钮属性以实现此目的吗?
您可以尝试覆盖ProcessCmdKey方法。 如果按alt,放开alt,然后按c键,则下面的命令应该起作用。
private bool altPressed;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (altPressed)
{
if (keyData == Keys.C)
{
this.SelectNextControl(ActiveControl, true, true, true, true);
altPressed = false;
return true;
}
}
if (keyData == (Keys.Menu | Keys.Alt))
{
altPressed = true;
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.