但是,我没有听到这样的听觉活动.
这是我的代码:
// 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))?
UPDATE
我现在有了这个代码:
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”键.
解决方法
从链接上方,他们使用一个按钮作为示例:
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.