How to use RaiseEvent KeyPress within DataReceivedEvent

  • 13 years ago
    Hi all,

    I will be receiving key pressing input trough serial port. How to raise an event of keypress when the data from serial port is received. When data comes on serial port DataReceivedEvent fires it i would parse the telegram, and depending on ID raise the PressKey event with the right argument (that being the type of key that was pressed ..for example escape button).

    and the second question :) , if the first can be done at to fire the preskey event on the current shown Windows form...cos datareceived event is in a class...

    Thanks in advance for your answers

  • 13 years ago

    Note this tidbit from the MSDN help on RaiseEvent:

    You cannot use RaiseEvent to raise events that are not explicitly declared in the module. For example, all forms inherit a Click event from System.Windows.Forms.Form, it cannot be raised using RaiseEvent in a derived form. If you declare a Click event in the form module, it shadows the form's own Click event. You can still invoke the form's Click event by calling the OnClick method.

    So you can't use RaiseEvent with the keypress event. What you want todo is make a standard call the the keypress event. The secret is to pass the right arguments. Try something like this in your DataReceivedEvent:

    Dim e As New System.Windows.Forms.KeyPressEventArgs(CChar("X"))

    Call form1_KeyPress(Me, e)

    Hope this helps!

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.” - E. W. Dijkstra