如何捕获.NET程序中的箭头键? [英] How do I capture the arrow keys in a .NET program?
问题描述
我有一个.NET程序,可以捕获向上和向下箭头键来移动SQL数据库。自从我输入以来,代码一直按预期工作。最近我遇到了一个问题,需要删除并重新安装Windows 10,从那时起,向上和向下箭头无法通过数据库工作。我正在运行Visual Studio和Windows 10,我的代码是:
I have a .NET program that captures the up and down arrow keys to move through a SQL database. The code has been working as intended since I entered, Recently I had a problem that required removing and reinstalling Windows 10 and since then the up and down arrows don't work through the database. I am running Visual Studio and Windows 10 and my code is:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.Up
DVD_ListBindingSource.MovePrevious()
e.Handled = True
Case Keys.Down
DVD_ListBindingSource.MoveNext()
e.Handled = True
End Select
End Sub
Not确定从哪里开始
我尝试过:
因为代码以前一直在工作,所以我不知道从哪里开始。我不确定是否有需要打开或关闭的注册表项,或者我是否需要调整我的代码。
Not sure where to go from here
What I have tried:
Because the code has been working previously I have no idea where to start. I'm not sure if there is a registry item that needs to be switched on or off, or if I need to adjust my code.
推荐答案
如果表单是处理关键事件时,表单也必须有 KeyPreview = True
,表单事件处理程序才能获得关键事件的第一次破解。否则,关键事件将直接转到具有焦点的控件,而不是表单。
If the form is handling the key events, the form is also going to have to have KeyPreview = True
for the form event handlers to get first crack at the key events. Otherwise, the key events will go straight to the control that has the focus, not to the form.
这篇关于如何捕获.NET程序中的箭头键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!