AdvancedHMI Software

General Category => Support Questions => Topic started by: MrPike on October 11, 2018, 10:39:29 AM

Title: Call KeyDown event from button
Post 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.

Code: [Select]
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
Title: Re: Call KeyDown event from button
Post by: Archie on October 11, 2018, 10:52:18 AM
Try this:
Code: [Select]
tbxIPaddress_KeyDown(sender, New System.EventArgs.Empty)
Title: Re: Call KeyDown event from button
Post by: MrPike on October 11, 2018, 11:48:52 AM
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
Title: Re: Call KeyDown event from button
Post by: Archie on October 11, 2018, 12:04:11 PM
I should have left off the keyword "new"
Code: [Select]
tbxIPaddress_KeyDown(sender, System.EventArgs.Empty)

or maybe even this:
Code: [Select]
New System.Windows.Forms.KeyEventArgs(Keys.A)
Title: Re: Call KeyDown event from button
Post by: MrPike on October 11, 2018, 01:21:37 PM
the later worked by substituting key.A for key.Enter.  Thank you

Code: [Select]
New System.Windows.Forms.KeyEventArgs(Keys.Enter)