Sub to handle the same event in different forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J. Moreno

    #1

    Sub to handle the same event in different forms

    I have an event handler (for keypress) and I want to use it multiple forms.

    What's the best way of doing this?

    I tried using

    Public Sub cmbHandleKeyPre ss _
    (Byval Sender as Object, ByVal e As
    System.Windows. Forms.KeyPressE ventArgs) _ Handles cmbMyMenu.Keypr ess,
    frmOther.cmbOth erMenu.KeyPress

    End Sub

    but I get a build error.

    Either I'm the first to think of this, or it's a really dumb thing to do,
    because I can't find anyone else asking about it...

    --
    J. Moreno
  • Dennis

    #2
    RE: Sub to handle the same event in different forms

    You might try creating (if you don't already have one) a general module class
    then put your event handling sub in this module which will make it available
    globally. Then in each form's new sub, use addhandler to add the
    eventhandling sub to the event you want. You would't need the "handles... ."
    at the end of the sub declaration.
    --
    Dennis in Houston


    "J. Moreno" wrote:
    I have an event handler (for keypress) and I want to use it multiple forms.
    >
    What's the best way of doing this?
    >
    I tried using
    >
    Public Sub cmbHandleKeyPre ss _
    (Byval Sender as Object, ByVal e As
    System.Windows. Forms.KeyPressE ventArgs) _ Handles cmbMyMenu.Keypr ess,
    frmOther.cmbOth erMenu.KeyPress
    >
    End Sub
    >
    but I get a build error.
    >
    Either I'm the first to think of this, or it's a really dumb thing to do,
    because I can't find anyone else asking about it...
    >
    --
    J. Moreno
    >

    Comment

    Working...