Handling events in VB.NET vs C#


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Handling events in VB.NET vs C#

  1. #1
    martin rydman Guest

    Handling events in VB.NET vs C#


    Hi all!

    I've been trying to figure out how to do the stuff below in C#. That is,
    declare an event with an arbitrary parameter-list, raise it, and, in a client,
    declare a variable WithEvents, and then consume the event. Actually, it's
    the parameter-list part that's important (specifically to be able to keep
    the arbitrary parameter-list).


    In component(CSIEFil):
    ----------------------
    Declare:
    Public Event SIEImportProgress(ByRef Message As String)

    Raise:
    RaiseEvent SIEImportProgress("Some message")


    In client:
    ----------
    Declare:
    Private WithEvents SIEFil As CSIEFil

    Consume:
    Private Sub SIEFil_SIEImportProgress(ByRef Message As String) Handles SIEFil.SIEImportProgress


    TIA!

    /Martin

  2. #2
    Bruce Guest

    Re: Handling events in VB.NET vs C#


    Martin,
    It should go something like this:

    In component(CSIEFil):
    public delegate void SIEImportProgressHandle(string Message);

    Declare:
    public event SIEImportProgressHandler SIEImportProgress;


    //Raise:
    SIEImportProgress("Some message");


    //In client:
    ----------
    Declare:
    Private CSIEFil SIEFil;
    SIEFil.SIEImportProgress+= new SIEImportProgressHandler (SIEFil_SIEImportProgress);

    //Consume:
    Private void SIEFil_SIEImportProgress(string strMessage)
    {
    //Put code here
    }

    Bruce


    "martin rydman" <martin@aprire.se> wrote:
    >
    >Hi all!
    >
    >I've been trying to figure out how to do the stuff below in C#. That is,
    >declare an event with an arbitrary parameter-list, raise it, and, in a client,
    >declare a variable WithEvents, and then consume the event. Actually, it's
    >the parameter-list part that's important (specifically to be able to keep
    >the arbitrary parameter-list).
    >
    >
    >In component(CSIEFil):
    >----------------------
    >Declare:
    >Public Event SIEImportProgress(ByRef Message As String)
    >
    >Raise:
    >RaiseEvent SIEImportProgress("Some message")
    >
    >
    >In client:
    >----------
    >Declare:
    >Private WithEvents SIEFil As CSIEFil
    >
    >Consume:
    >Private Sub SIEFil_SIEImportProgress(ByRef Message As String) Handles SIEFil.SIEImportProgress
    >
    >
    >TIA!
    >
    >/Martin



  3. #3
    martin rydman Guest

    Re: Handling events in VB.NET vs C#


    Hi Bruce!

    Thanks!

    /M

    "Bruce" <BruceHaslam@Cox.net> wrote:
    >
    >Martin,
    >It should go something like this:
    >
    >In component(CSIEFil):
    >public delegate void SIEImportProgressHandle(string Message);
    >
    >Declare:
    >public event SIEImportProgressHandler SIEImportProgress;
    >
    >
    >//Raise:
    >SIEImportProgress("Some message");
    >
    >
    >//In client:
    >----------
    >Declare:
    >Private CSIEFil SIEFil;
    >SIEFil.SIEImportProgress+= new SIEImportProgressHandler (SIEFil_SIEImportProgress);
    >
    >//Consume:
    >Private void SIEFil_SIEImportProgress(string strMessage)
    >{
    > //Put code here
    >}
    >
    >Bruce
    >
    >
    >"martin rydman" <martin@aprire.se> wrote:
    >>
    >>Hi all!
    >>
    >>I've been trying to figure out how to do the stuff below in C#. That is,
    >>declare an event with an arbitrary parameter-list, raise it, and, in a

    client,
    >>declare a variable WithEvents, and then consume the event. Actually, it's
    >>the parameter-list part that's important (specifically to be able to keep
    >>the arbitrary parameter-list).
    >>
    >>
    >>In component(CSIEFil):
    >>----------------------
    >>Declare:
    >>Public Event SIEImportProgress(ByRef Message As String)
    >>
    >>Raise:
    >>RaiseEvent SIEImportProgress("Some message")
    >>
    >>
    >>In client:
    >>----------
    >>Declare:
    >>Private WithEvents SIEFil As CSIEFil
    >>
    >>Consume:
    >>Private Sub SIEFil_SIEImportProgress(ByRef Message As String) Handles SIEFil.SIEImportProgress
    >>
    >>
    >>TIA!
    >>
    >>/Martin

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center