Home All Groups Group Topic Archive Search About
Author
11 Jul 2006 11:31 AM
Water Cooler v2
Am I right in guessing that there is no direct C# equivalant for the
'WithEvents' VB keyword. The substitute is to add event handlers to the
delegate instances that are the public members of the class.

For instance,

Public WithEvents ObjFoo As New ClassFoo

Public Sub ObjFoo_FooDone(ByVal sender as Object, ByVal e As EventArgs)
    Console.WriteLine("Foo has been done.")
End Sub



public ClassFoo ObjFoo;

public void Init()
{
ObjFoo = new ClassFoo();
ObjFoo.FooDone += new TheClassOfWhichFooDoneIsAType(fooDone);
}


public void fooDone(Object s, EventArgs e)
{
Console.WriteLine("Foo has been done.");
}

Author
11 Jul 2006 11:39 AM
Peter Bromberg [C# MVP]
Water Cooler,
You are correct. And it's been beaten to death, if you search the group.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Show quoteHide quote
"Water Cooler v2" wrote:

> Am I right in guessing that there is no direct C# equivalant for the
> 'WithEvents' VB keyword. The substitute is to add event handlers to the
> delegate instances that are the public members of the class.
>
> For instance,
>
> Public WithEvents ObjFoo As New ClassFoo
>
> Public Sub ObjFoo_FooDone(ByVal sender as Object, ByVal e As EventArgs)
>     Console.WriteLine("Foo has been done.")
> End Sub
>
>
>
> public ClassFoo ObjFoo;
>
> public void Init()
> {
> ObjFoo = new ClassFoo();
> ObjFoo.FooDone += new TheClassOfWhichFooDoneIsAType(fooDone);
> }
>
>
> public void fooDone(Object s, EventArgs e)
> {
> Console.WriteLine("Foo has been done.");
> }
>
>
Author
11 Jul 2006 11:52 AM
Water Cooler v2
Peter wrote:
> Water Cooler,
> You are correct. And it's been beaten to death, if you search the group.
> Peter


Thank you, Peter.
Author
11 Jul 2006 1:23 PM
Adam Clauss
WithEvents?

I've never even heard of it... I'm gonna have to go dig this up.

-Adam



Show quoteHide quote
"Peter Bromberg [C# MVP]" <pbromberg@yahoo.nospammin.com> wrote in message
news:03DCE61A-D187-4BF0-947B-9A3879314800@microsoft.com...
> Water Cooler,
> You are correct. And it's been beaten to death, if you search the group.
> Peter
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "Water Cooler v2" wrote:
>
>> Am I right in guessing that there is no direct C# equivalant for the
>> 'WithEvents' VB keyword. The substitute is to add event handlers to the
>> delegate instances that are the public members of the class.
>>
>> For instance,
>>
>> Public WithEvents ObjFoo As New ClassFoo
>>
>> Public Sub ObjFoo_FooDone(ByVal sender as Object, ByVal e As EventArgs)
>>     Console.WriteLine("Foo has been done.")
>> End Sub
>>
>>
>>
>> public ClassFoo ObjFoo;
>>
>> public void Init()
>> {
>> ObjFoo = new ClassFoo();
>> ObjFoo.FooDone += new TheClassOfWhichFooDoneIsAType(fooDone);
>> }
>>
>>
>> public void fooDone(Object s, EventArgs e)
>> {
>> Console.WriteLine("Foo has been done.");
>> }
>>
>>
Author
11 Jul 2006 3:37 PM
Wamba
Adam Clauss wrote:
> WithEvents?
>
Yes, in Vb.net you need to declare a class with this attribute if u
like to work with events.
Author
11 Jul 2006 3:56 PM
Branco Medeiros
Wamba wrote:
> Adam Clauss wrote:
> > WithEvents?
> >
> Yes, in Vb.net you need to declare a class with this attribute if u
> like to work with events.

Well, you don't *need*, it's a feature. If you don't want to use
WithEvents, you may allways explicitly add your event handlers, if
you're so inclined, just like the example in C#.

Regards,

Branco.
Author
11 Jul 2006 5:44 PM
Michael D. Ober
Sometime's it's useful to declare the class object "withevents" to let the
IDE assist in the event syntax.  Other times, use the AddHandler method for
more control over when an event becomes eligible for firing.

Mike Ober.

Show quoteHide quote
"Branco Medeiros" <branco.medei***@gmail.com> wrote in message
news:1152633389.470627.325600@s13g2000cwa.googlegroups.com...
>
> Wamba wrote:
> > Adam Clauss wrote:
> > > WithEvents?
> > >
> > Yes, in Vb.net you need to declare a class with this attribute if u
> > like to work with events.
>
> Well, you don't *need*, it's a feature. If you don't want to use
> WithEvents, you may allways explicitly add your event handlers, if
> you're so inclined, just like the example in C#.
>
> Regards,
>
> Branco.
>