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.");
} 6 1851
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.");
}
Peter wrote:
Water Cooler,
You are correct. And it's been beaten to death, if you search the group.
Peter
Thank you, Peter.
WithEvents?
I've never even heard of it... I'm gonna have to go dig this up.
-Adam
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:03**********************************@microsof t.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."); }
Adam Clauss wrote:
WithEvents?
Yes, in Vb.net you need to declare a class with this attribute if u
like to work with events.
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.
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.
"Branco Medeiros" <br*************@gmail.comwrote in message
news:11**********************@s13g2000cwa.googlegr oups.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jonas |
last post by:
This works fine in Win XP but does not work at all in Win 98.
Private WithEvents objIExplorer As InternetExplorer
I have to do it like this to get it to work in Win 98
Dim objIExplorer As...
|
by: Jakob Bengtsson |
last post by:
Hi,
I have a form (which cannot be serialized).
In the form's code I declare an object like this (never
mind the object nor class name, it's for illustration
only):
Private WithEvents...
|
by: Bradley Grant |
last post by:
I am trying to write a program to access a device through
USB port, there is some Visual Basic program examples that
work with the device, but I am trying to write a program
using C#, no luck yet,...
|
by: Tee |
last post by:
Hi,
I am converting a code from VB to C#.
in VB, it's
Private WithEvents MyButton As Button
what's the code in C# ?
I can't get the replacement for the "WithEvents" in C#.
|
by: Peter |
last post by:
Hello,
Thanks for reviewing my question. I am following KB article about creating
a custom control and its source code is in VB. I got to a part where I have
the following:
Private...
|
by: Steve |
last post by:
Hello,
I have been experimenting/learning to use aspx with and
without VS2003. In VS 2003 I created a simple
webform/application which contains a listbox and a label.
I populate the listbox...
|
by: Shapper |
last post by:
Hello,
I have an aspx.vb page with this code:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Menu1 As MenuControl.Web.UI.Menu
...
If I have my code in the aspx...
|
by: |
last post by:
Is there any additional overhead for declaring a variable using the
WithEvents keyword even if none of the events are being handled?
|
by: Bob Day |
last post by:
Using VS 2003, VB.NET, MSDE
If an event is raised in a class that was NOT instantiated with the
WithEvents key word, is that event effectively ignored?
Or, another way to phrase the question,...
|
by: DareDevil |
last post by:
Class MyClas
Friend ReadOnly WithEvents MyObject as AnotherClas
..
End Clas
I have a VB.NET class that has a readonly object (i.e. It can only be assigned in the constructor). This enables me...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |