Results 1 to 3 of 3

Thread: *RESOLVED* Events with no parameters and sender & e

  1. #1

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    *RESOLVED* Events with no parameters and sender & e

    If I have events with no arguments/parameters should I still be using sender and e to conform to the whole .NET scheme?

    VB Code:
    1. Public Event Refresh() 'in VB6
    2.  
    3. 'should I translate it to:
    4. Public Event Refresh(sender as Object, e as System.EventArgs) 'in net

    What if I do have things I want to pass, should I pass them as an object (sender) or define an inherited EventArgs?

    If I know what object I want to pass back as the sender should I declare it as that type or as the generic object?

    By the questions keep coming.
    Last edited by Edneeis; Aug 15th, 2002 at 04:47 PM.

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Well as a rule you pass the calling object as the sender and any other parameters in the EventArgs object. You can pass nothing to the EventArgs if needs be:-

    RaiseEvent Test(Me, Nothing)

    The SDK documentation says you need the following for an event:-

    A class that holds event data, named EventNameEventArgs. This class must derive from System.EventArgs.
    A delegate for the event, named EventNameEventHandler.
    A class that raises the event. This class must provide:
    An event declaration.
    [Visual Basic]
    Public Event EventName As EventNameEventHandler
    A method named OnEventName that raises the event.

    It goes on to explain how to create your own eventargs:-

    To provide event functionality

    Define a class that provides data for the event. This class must derive from System.EventArgs, which is the base class for event data. An example follows.
    Note This step is not needed if an event data class already exists for the event or if there is no data associated with your event. If there is no event data, use the base class System.EventArgs.
    [Visual Basic]
    Public Class AlarmEventArgs
    Inherits EventArgs
    Private nrings As Integer = 0
    Private _snoozePressed As Boolean = False

    'Properties.
    Public ReadOnly Property AlarmText() As String
    ...
    End Property

    Public ReadOnly Property NumRings() As Integer
    ...
    End Property

    Public ReadOnly Property SnoozePressed() As Boolean
    ...
    End Property
    ...
    End Class

    Theres alot more and if you have the .Net SDK a quick search will bring this stuff up. Worth a read.

  3. #3

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I actually read that and have been pretty much doing that, I guess me question is should I be doing that for EVERY event. I guess so, it just seems like overkill sometimes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width