AdvancedHMI Software
General Category => Support Questions => Topic started by: MrPike on October 11, 2018, 10:39:29 AM
-
I have a basic vb question that I cannot get right. I want to call the KeyDown event of a textbox with a button click. This code throws an "Invalid Cast exception was unhandled" when I press the button. I assume I do not have the correct arguments but not sure what to use. Any help is appreciated, Thanks.
Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click 'give the user the option to click a "connect" button
tbxIPaddress_KeyDown(sender, New System.EventArgs())
End Sub
-
Try this:
tbxIPaddress_KeyDown(sender, New System.EventArgs.Empty)
-
that doesn't seem to compile. I get the blue squiggly under .Empty from intellisense.
Here is the details of the exception from the original code
-
I should have left off the keyword "new"
tbxIPaddress_KeyDown(sender, System.EventArgs.Empty)
or maybe even this:
New System.Windows.Forms.KeyEventArgs(Keys.A)
-
the later worked by substituting key.A for key.Enter. Thank you
New System.Windows.Forms.KeyEventArgs(Keys.Enter)