WithEvents

  • Thread starter Thread starter Water Cooler v2
  • Start date Start date
W

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.");
}
 
Water Cooler,
You are correct. And it's been beaten to death, if you search the group.
Peter
 
Wamba said:
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.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top