CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Event declaration and firing

    In VB I need to write 2 lines in Class to declare and fire event. In client (form for instance) I need to create an object with events from my class and write something in event procedure (3 more lines of code). Something like that:
    'in class
    <vbcode>
    Public Event myEvent
    'in some procedure
    RaiseEvent myEvent
    'in form
    Private WithEvents obj As myClass
    obj=New myClass
    Private Sub obj_myEvent()
    MessageBox.Show("Event fired")
    End Sub
    </vbcode>

    How do I do the same stuff in C#? Unfortunately I cannot find any simple sample in my books.

    Thank you
    Vlad

  2. #2
    Join Date
    May 2002
    Location
    Atlanta,GA
    Posts
    262

    Re: Event declaration and firing

    Originally posted by vchapran
    In VB I need to write 2 lines in Class to declare and fire event. In client (form for instance) I need to create an object with events from my class and write something in event procedure (3 more lines of code). Something like that:
    'in class
    <vbcode>
    Public Event myEvent
    'in some procedure
    RaiseEvent myEvent
    'in form
    Private WithEvents obj As myClass
    obj=New myClass
    Private Sub obj_myEvent()
    MessageBox.Show("Event fired")
    End Sub
    </vbcode>

    How do I do the same stuff in C#? Unfortunately I cannot find any simple sample in my books.

    Thank you
    Vlad
    Here's a shot. You will have to modifiy this slightly to fit your needs

    Code:
    public eventname myevent;
    
    /* In some procedure */
    myevent(arguments);
    I don't really understand what the rest of your VBCode is doing.
    Jared

  3. #3
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632
    Could you please provide a sample containing declaration and trowing event in Class and its interception in Form as I described in my original post.
    If I'm asking for help with a such simple stuff, it means that I'm a beginner and if your code doesn't work (and it really doesn't - highlights 'eventname', 'arguments'). Probably I have to declare somehow arguments, but I have no clue what 'eventname' means. If it's the name of event then what is 'myevent'?
    Maybe I have to add something with 'using' and then eventname will work?
    So, I'm asking for working sample, please.
    Vlad

  4. #4
    Join Date
    May 2002
    Location
    Atlanta,GA
    Posts
    262
    Originally posted by vchapran
    Could you please provide a sample containing declaration and trowing event in Class and its interception in Form as I described in my original post.
    If I'm asking for help with a such simple stuff, it means that I'm a beginner and if your code doesn't work (and it really doesn't - highlights 'eventname', 'arguments'). Probably I have to declare somehow arguments, but I have no clue what 'eventname' means. If it's the name of event then what is 'myevent'?
    Maybe I have to add something with 'using' and then eventname will work?
    So, I'm asking for working sample, please.
    Vlad
    I was expecting you to fill in the names like "eventname" with the event you wanint to create.

    However here is an article that has several full working samples
    http://www.codeguru.com/cs_delegates/Delegate.html
    Jared

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

Featured