c# - 有些键盘比其他键盘更啰嗦吗?

标签 c# winforms arrow-keys beep keyeventargs

首席开发人员说,当他使用我的应用程序时,当他通过方向箭头键在 TableLayoutPanel 上的文本框之间移动时,他的键盘会发出哔哔声。

但是,我没有听到这样的听觉事件。

这是我的代码:

// Had to intercept Up and Down arrows from Windows
private void textBoxPlatypi_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
    TextBox tb = (TextBox)sender;

    if (e.KeyCode.Equals(Keys.Up)) {
        SetFocusOneRowUp(tb.Name);
        return;
    }
    if (e.KeyCode.Equals(Keys.Down)) {
        SetFocusOneRowDown(tb.Name);
        return;
    }
}

private void textBoxPlatypi_KeyDown(object sender, KeyEventArgs e) {
    TextBox tb = (TextBox)sender;

    if (e.KeyCode.Equals(Keys.Left)) {
        SetFocusOneColumnBack(tb.Name);
        e.Handled = true;
        return;
    }
    if (e.KeyCode.Equals(Keys.Right)) {
        SetFocusOneColumnForward(tb.Name);
        e.Handled = true;
        return;
    }
}

..他认为也许我需要“e.Handled”,但这在 PreviewKeyDown 事件中不可用。

有没有办法抑制哔哔声(这显然只发生在某些键盘或特定设置下(他使用的是 Windows7,我仍在使用 XP))?

更新

我现在得到了这段代码:

private void textBoxPlatypus1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
    switch (e.KeyCode) {
        case Keys.Down:
        case Keys.Up:
            e.IsInputKey = true;
            break;
    }
}

private void textBoxPlatypus1_KeyDown(object sender, KeyEventArgs e) {
    TextBox tb = (TextBox)sender;

    if (e.KeyCode.Equals(Keys.Up)) {
        SetFocusOneRowUp(tb.Name);
        e.Handled = true;
        return;
    }
    if (e.KeyCode.Equals(Keys.Down)) {
        SetFocusOneRowDown(tb.Name);
        e.Handled = true;
        return;
    }

    if (e.KeyCode.Equals(Keys.Left)) {
        SetFocusOneColumnBack(tb.Name);
        e.Handled = true;
        return;
    }
    if (e.KeyCode.Equals(Keys.Right)) {
        SetFocusOneColumnForward(tb.Name);
        e.Handled = true;
        return;
    }
}

...但他仍然听到哔哔声(我没有)。

他在阿拉斯加使用 Windows 7;我在加利福尼亚并使用 XP。我不知道是否存在某些组合/不匹配问题...

再次更新

我知道这可能会让一些人感到震惊,但阿拉斯加/加利福尼亚的脱节与此无关。我现在也能听到哔哔声,但不是方向键发出的。当在 TextBox 中输入一个值,然后,如果该文本框已经有一个字符,焦点将移动到下一个 textBox 并在那里输入值(这是我的代码导致这种情况发生)。但是恼人的哔哔声似乎是随机的——我还没有弄清楚它发出哔哔声的模式(有时会,有时不会)……有没有人遇到过类似的事情,或者,更好的是,知道如何抑制蜂鸣声?我所做的只是按下键盘上方的“1”或“2”键。

最佳答案

没有办法在PreviewKeyDownEvent像正常的 KeyDown 事件一样处理/抑制 KeyEvent。文档建议将 PreviewKeyDownEventArgs.IsInputKey 属性设置为 true,以便处理 KeyDown 事件中通常不可用的按键操作。

从上面的链接,他们使用一个按钮作为例子:

Some key presses, such as the TAB, RETURN, ESC, and arrow keys, are typically ignored by some controls because they are not considered input key presses... By handling the PreviewKeyDown event for a Button and setting the IsInputKey property to true, you can raise the KeyDown event when the arrow keys are pressed. However, if you handle the arrow keys, the focus will no longer move to the previous or next control.

关于c# - 有些键盘比其他键盘更啰嗦吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10660945/

相关文章:

c# - 如何使用 C#.Net 更改已具有数据的 DataTable 的列数据类型?

c# - 有没有办法在另一种形式上显示一种形式的一部分?

javascript - 如何检测浏览器中是否支持箭头键的按键?

C# 抽象类继承

c# - 使用 Cookie 的购物车

c# - XmlSerializer - 包含文本 + xml + 文本的节点

c# - 尝试使用 VB6 Form 调用 OLEDB 提供程序时应用程序消失

.net - 使用 .NET "WinForms"SplitContainer 控件,如何动态隐藏面板?

python - 在 python shell 中按箭头键时看到转义字符