在主窗体中,我有快捷键(ctrl + S)用于将数据保存在数据库中。对于组合框(ctrl + 字母)是默认操作。如何禁用组合框的快捷键?
更新:
在 keyPress 事件上我们可以这样做
if (ModifierKeys == Keys.Control)
{
e.Handled = true;
}
最佳答案
您可以尝试重写主窗体的 ProcessCmdKey 方法:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
const int WM_KEYDOWN = 0x100;
if (keyData == (Keys.Control | Keys.S)) {
if (msg.Msg == WM_KEYDOWN)
MySaveDataToDatabase(); // <- Do your save command
return true; // <- Stop processing the WM_KeyDown message for Ctrl + S (and shortcut as well)
}
// All other key messages process as usual
return base.ProcessCmdKey(ref msg, keyData);
}
关于c# - 如何使用 Windows 应用程序在 C# 中禁用 ComboBox 上的快捷键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17562977/