Click to See Complete Forum and Search --> : Event declaration and firing


vchapran
July 7th, 2002, 02:31 PM
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

jparsons
July 7th, 2002, 03:41 PM
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


public eventname myevent;

/* In some procedure */
myevent(arguments);



I don't really understand what the rest of your VBCode is doing.

vchapran
July 7th, 2002, 09:58 PM
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

jparsons
July 8th, 2002, 06:14 AM
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