Q: Error Closing VB Form - Unable to Cast "EventArgs" to "KeyEventArgs" I have been working on a VB program that will help our internal operations, within this program i have created a form (Child Form) that takes some information and saves it into a database. 
I have recently added the .KeyDown to my main box so that the user can hit enter rather than having to press a button. (See below for the header). (This is the first field you enter)
 Private Sub Model_Family_Validate(sender As Object, e As KeyEventArgs) Handles txtbox_modelfamily.Validated, txtbox_modelfamily.KeyDown 
On my Parent Form i have a log out button, that is EventArgs, if i enter my Child form and then log out it crashes saying 
 An unhandled exception of type 'System.InvalidCastException' occurred in System.Windows.Forms.dll
Additional information: Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.KeyEventArgs'.
If i remove my KeyDown event and the Keyeventargs to Eventargs it works fine.


*

*Even if i just enter this form and then log out it errors, i do not need to do anything in the child form.

*The reason i am using KeyEventArgs is because i need to know that the enter key has been pressed

*The Parent Form has a ribbon at the top with various buttons along with a drop down menu, containing further options. I am using one of the drop down options.


The other strange thing is i can press any other button apart from the log out.
Public Sub LogOff_Click(sender As Object, e As EventArgs) Handles btn_m_logoff.Click

    Me.Close()
    frm_login.Show()

    frm_login.txtbox_loginpassword.Text = ""

End Sub

Can anyone see why it is doing this?
Any further information required then please let me know, Thanks.

A: If I understand your question correctly, you are trying to log off when the enter button is clicked. You also have a button that says "Log off" that is supposed to perform the same function as pressing enter. If so, you should be using the Me.AcceptButton property of the form and set it to the existing log off button. You can either do this in the design mode or during runtime.
This property should then run the code in the Private Sub Model_Family_Validate sub-routine whenever Enter is pressed.

A: Thank you everyone for your answers, this issue is now fixed. I have turned Options Strict On and it has highlighted the issue, this has now been rectified. 
I split the two events into their own sections and its now as i want.
