Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Raising Events from a class library

Raising Events from a class library

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xbiplav
    wrote on last edited by
    #1

    I am in a scenario where I have made a class library (*.dll) file. At some point I need to raise an event( from within a class of the *.dll library) of a class(Like Event in the Class shown Below) which is outside or out of the scope of the *.dll library. How do I do it? Do I need to add interface in that particular class of the *.dll library and implement in the calling class or any technique? Does anybody have some idea? Public Class SomeClass Public Event SomeEvent .......... End Class

    D 1 Reply Last reply
    0
    • X xbiplav

      I am in a scenario where I have made a class library (*.dll) file. At some point I need to raise an event( from within a class of the *.dll library) of a class(Like Event in the Class shown Below) which is outside or out of the scope of the *.dll library. How do I do it? Do I need to add interface in that particular class of the *.dll library and implement in the calling class or any technique? Does anybody have some idea? Public Class SomeClass Public Event SomeEvent .......... End Class

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      There's no magical difference between events in a Form and events in a class library. A Form is just another class. The code snippet you've posted is correct. You just have to keep going and flesh it out with an Event Args class of your own making and add some code that raises the event.

      Public Class SomeClass

      Public Event WorkCompleted(ByVal e As WorkCompletedEventArgs)
      
      ...
          RaiseEvent WorkCompleted(New WorkCompletedEventArgs(someValue, someOtherValue))
      ...
      

      End Class

      Public Class WorkCompletedEventArgs
      ' Expose Public properties that will
      ' return values to the subscriber.
      ' You might want to include a New (constructor)
      ' that set's these values instead of just
      ' relying on an empty constructor.

      Public Sub New(ByVal value1 As Integer, ByVal value2 As String)
          Me.myValue = value1
          Me.myString = value2
      End Sub
      

      End Class

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      modified on Tuesday, April 28, 2009 12:38 AM

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups