方法无法处理事件 "KeyDown because they do not have a compatible signature"

Method cannot handle event "KeyDown because they do not have a compatible signature"

所以我正在尝试编写一个程序来检测我何时按下 down 并将 said 的值分配给变量,然后将其输出到消息框中,但是我不能这样做,因为出现以下错误:

方法 'Main_KeyDown' 无法处理事件 'KeyDown',因为它们没有兼容的签名。

我不确定这是为什么或为什么会发生这种情况,当我使用 KeyPress 事件时它不会抛出错误,但也会发生为什么我尝试使用 KeyUp - 但是对于这个程序我需要它使用 KeyDown。

这里是有问题的代码:

Private Sub Main_KeyDown(sender As Object, e As KeyPressEventArgs) Handles MyBase.KeyDown
    _keyDown = e.KeyChar
    MsgBox(_keyDown)
End Sub

我对这里的想法非常迷茫,以前从未遇到过这个错误,我尝试过谷歌搜索并查看其他 Overflow 帖子,但 none 有帮助。

该方法对 KeyDown 事件无效,因为该事件(以及 KeyUp)的签名与 KeyPress 的签名不同

改用

Private Sub Main_KeyDown(sender As Object,e As KeyEventArgs) Handles MyBase.KeyDown

在此处查找 differences between KeyDown, KeyPress and KeyUp