Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3795760
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:07:58+00:00 2026-05-19T13:07:58+00:00

I would like to do something like the following: Public Class Form1 Public Event

  • 0

I would like to do something like the following:

Public Class Form1
    Public Event Evt1(ByVal c As c1)
    Public Event Evt2(ByVal c As c2)

    Private Sub OnEvt1OrEvt2(ByVal c As c1) Handles Me.Evt1, Me.Evt2
    End Sub 
End Class

Public Class c1
End Class

Public Class c2
    Inherits c1
End Class

However, it seems to be invalid syntax, as the signature of OnEvt1OrEvt2 doesn’t match that of Evt2.

Is there any way to achieve this?

Edit: The above code seems to work fine for everyone but me, but it doesn’t compile for me in VS2005 SP1.

The error message is something like:

Error BC31029: The method ‘Private Sub OnEvt1OrEvt2(c As
WindowsApplication1.c1)’ can not handle
the event ‘Public Event Evt2(c As
WindowsApplication1.c2)’ because the
signatures do not match.

Edit 2:

I have found this in msdn,
vb-related:

http://msdn.microsoft.com/en-us/library/ms973905.aspx

The code in the Form Load assigns
values to the Name property of the
three Bucket objects. It also calls
AddHandler to direct all of the
Overflowing events to the
HandleOverflow procedure. As you can
see, a single event handler can handle
multiple events, as long as all of the
events have compatible argument lists.

(…)

Copyright © 2002 Informant
Communications Group and Microsoft
Corporation

(Emphasis mine)

No word about what two “compatible argument lists” exactly are, though.

Edit 3:

OK, I found it:
http://msdn.microsoft.com/en-us/library/ms364068%28v=vs.80%29.aspx#vb9overview_topic10

Relaxed Delegates

When creating a delegate using
AddressOf or Handles in Visual Basic
8.0, one of the methods targeted for binding to the delegate identifier
must exactly match the signature of
the delegate’s type.

It was added in VB9.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:07:59+00:00Added an answer on May 19, 2026 at 1:07 pm

    In order for this to work, you would need to define your event such that the parameter is passed as type Object, and then perform a casting operation within the event handler.

    OR you could define an interface common to both C1 and C2, and use that as the parameter. You could then either use the reference “as-is” if the methods defined on the interface are suitable, or you would once again find yourself performing a casting operation.

    Note that if you define an interface with the common methods, and if these common methods are all that is required for use by the event handler, then you do not need to perform any sort of “TypeOf” determination in order to handle the event.

    All that said, I know that it is best, if possible, to follow the Event signature standard established within .NET wherever possible:

    Public Event SomethingHappened(ByVal Sender as Object, byVal e As System.EventArgs)
    

    It looks to me like you might create a class (or classes) which inherits from System.EventArgs, and then define a custom property to access your custom parameter. This way, you can still pass a reference to the client object in the Sender parameter, and then access your custom parameter thus:

    Public Class MyCustomEventArgs
        Inherits System.EventArgs
    
        Private _MyCustomInterface As ICustomInterface
    
        Public Property Myproperty As ICustomInterface
            Get As ICustomInterface
                Return _MyCustomInterface
            End Get
            Let(ByVal value As ICustomInterface)
                _MyCustomInterface = value
            End Let
        End Property
    End Class
    
    Public Sub HandleMyEvent(ByVal Sender As Object, byVal e As MyCustomEventArgs) Handles MyEvent
        Dim MyCustom Interface As ICustomInterface
        MyCustominterface = e.TheCustominterface
        MyCustominterface.DoSomething
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: Public Class Form1 Private Function Step1_Execute() As Boolean Return
Is it possible to do something like the following: public class ChildClass : BaseClass
I have something like the following: @RunWith(AllTestsRunner.class) public class AllTests { } in which
I would like to use NHibernate Automapper to map the following class: public class
I would like to do something like the following with spark. <viewdata model=IList[[string]] />
I would like to use something like the following: SELECT city FROM cities WHERE
I would like to do something like the following: if params[:entry].include? (http || www
Would it be possible to do something like the following in c#? Basically TParent
I have a file template.txt which contains the following: Hello ${something} I would like
I have the following code: public class Search { private Desktop desktop = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.