Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Using shortkeys with switch form controls

Hi, i'm using VB.Net 2005.  I have an application that controls several valves so I'm using digital output to turn them on and off.  Right now I have an On/Off button and an led to indicate whether the output is high or low.  With the button i can use a shortkey and it works.  But i would like to change from a button to a switch and still use the shortkey.  However it gives me a build error when i tried.  Here is how i'm handling the keydown event:
 

Private

Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

 

If e.KeyCode = Keys.F1 Then

Valve1_Switch_StateChanged(sender, e)

End If

When i did this with the button_click event it worked but when i do this with the switch i get this error when trying to build:

 Value of type 'System.Windows.Forms.KeyEventArgs' cannot be converted to 'NationalInstruments.UI.ActionEventArgs'. 

Is there any way around this?

 

Thanks,

BienoJ



Message Edited by BienoJ on 04-17-2008 11:21 AM
0 Kudos
Message 1 of 3
(3,825 Views)
Hi BienoJ,
 
You need to create a new instance of the ActionEventArgs type and use that to send into your switch changed event handler. So you should say something like:

If e.KeyCode = Keys.F1 Then
   D
im myArgs As ActionEventArgs = New ActionEventArgs(UI.Action.ByKeyboard)
  
Switch1_StateChanged(sender, myArgs)
End If

Best Regards,



Message Edited by Jonathan N on 04-17-2008 11:59 AM
Jonathan N.
National Instruments
0 Kudos
Message 2 of 3
(3,820 Views)
I actually figured out another way to do it but thank you for the quick response.

BienoJ
0 Kudos
Message 3 of 3
(3,813 Views)