c# - 如何使用 Windows 应用程序在 C# 中禁用 ComboBox 上的快捷键?

标签 c# winforms combobox keyboard-shortcuts

在主窗体中,我有快捷键(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/

相关文章:

c# - 具有多对多和 IncludeMembers 的自动映射器

c# - 创建一种从另一个线程安全访问控件的方法

c# - 创建一个有效的数据类型,用于按初始和结果单位 C# 查找转换因子

c# - 数据源很大时DataSet的使用?

c# - C#-mscorlib.dll中未处理的异常

c# - 以编程方式计算 DOCX 文档中具有特定样式的字符/单词/段落的数量

c# - SQL 超时在不应该的时候过期

datagridview - 在 ComboBox 中更改选择时,在 DataGridView 中提交更改

wpf:获取组合框值

combobox - JavaFX 组合框 setButtonCell