Sub to handle the same event in different forms

Discussion in 'Microsoft VB .NET' started by J. Moreno, Aug 18, 2006.

  1. J. Moreno

    J. Moreno Guest

    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 cmbHandleKeyPress _
    (Byval Sender as Object, ByVal e As
    System.Windows.Forms.KeyPressEventArgs) _ Handles cmbMyMenu.Keypress,
    frmOther.cmbOtherMenu.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
     
    J. Moreno, Aug 18, 2006
    #1
    1. Advertisements

  2. J. Moreno

    Guest Guest

    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 cmbHandleKeyPress _
    > (Byval Sender as Object, ByVal e As
    > System.Windows.Forms.KeyPressEventArgs) _ Handles cmbMyMenu.Keypress,
    > frmOther.cmbOtherMenu.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
    >
     
    Guest, Aug 19, 2006
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tmaster
    Replies:
    4
    Views:
    195
    manasvin
    Jan 6, 2004
  2. tmaster
    Replies:
    1
    Views:
    182
    Armin Zingler
    Jan 6, 2004
  3. Mick Doherty

    Re: System.Windows.Forms.TabPage: handle LostFocus event

    Mick Doherty, Sep 10, 2004, in forum: Microsoft VB .NET
    Replies:
    0
    Views:
    949
    Mick Doherty
    Sep 10, 2004
  4. Siv
    Replies:
    10
    Views:
    307
  5. Replies:
    6
    Views:
    166
Loading...

Share This Page