'Unable to cast object of type 'System.EventArgs' to type
In my Form_Load
AddHandler KeyDown, AddressOf Form1_KeyDown
RaiseEvent KeyDown(Me, e)
Event KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.KeyCode = Keys.Control Then
MsgBox("test")
End If
End Sub
I get this error : Unable to cast object of type 'System.EventArgs' to type
What should i do to catch keydown event?
Here is my code :
I have the form load function :
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler KeyDown, AddressOf Form1_KeyDown
RaiseEvent KeyDown(Me, e)
End Sub
I have the event declaration :
Event KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
And the function which should open MsgBox When control key is pressed :
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.KeyCode = Keys.Control Then
MsgBox("test")
End If
End Sub
But I have this error : Unable to cast object of type 'System.EventArgs' to type
So i do not know what should i do
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|