WithEvents in C#.NET

N

news.microsoft.com

Hi,

I want to use a COM component in my C#.NET project. The sample VB code of
the COM component declares it as -
Public WithEvents ePrint1 As LEADePrint

How do I do the equivalent in C#.NET? Do I need to bother about the
WithEvents part (I believe there is no C# equivalent for this), do I simply
do
LEADePrint ePrint1

and then setup the events that I want to handle in the normal way
(delegates)?

Thanks

Vani
 
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

Hi,
Hi,

I want to use a COM component in my C#.NET project. The sample VB code of
the COM component declares it as -
Public WithEvents ePrint1 As LEADePrint

How do I do the equivalent in C#.NET? Do I need to bother about the
WithEvents part (I believe there is no C# equivalent for this), do I simply
do
LEADePrint ePrint1

and then setup the events that I want to handle in the normal way
(delegates)?

Thanks

Vani

There's no equivalent of WithEvents in C# because it has default
event handling.

If You look in "Object Browser" then you'll find COM delegates.
If there will not be a *EventArgs* for them then probably You'll find
an interfaces with delegate definitions.

Regards

Marcin
 
B

Branimir Giurov

There isn't WithEvents in C# - just decare the variable and then attach the
event handlers.

Cheers,
Branimir
 
D

Doknjas

Yes,
Here's a block of VB.NET code with the equivalent C# code following
that courtesy of Instant C# (since I didn't include the
"InitializeComponent" method there's a 'ToDo' task in the converted
code):

VB:
Private WithEvents x As y

Private Sub z1(sender As Object, e As System.EventArgs) Handles x.a
End Sub
Private Function z2(sender As Object, e As System.EventArgs) As
Integer Handles x.b, x.c
End Function

C#:
private y x;

//INSTANT C# TODO TASK: Insert the following converted event handlers
at the end of the 'InitializeComponent' method for forms or into a
constructor for other classes:
//x.a += new System.EventHandler(y);
//x.b += new System.EventHandler(z);
//x.c += new System.EventHandler(z);

//ORIGINAL LINE: Private Sub z1(sender As Object, e As
System.EventArgs) Handles x.a
private void z1(object sender, System.EventArgs e)
{
}
//ORIGINAL LINE: Private Function z2(sender As Object, e As
System.EventArgs) As Integer Handles x.b, x.c
private int z2(object sender, System.EventArgs e)
{
}
 
D

Doknjas

Sorry - I was messing with the output - the C# code is:

private y x;

//INSTANT C# TODO TASK: Insert the following converted event handlers
at the end of the 'InitializeComponent' method for forms or into a
constructor for other classes:
//x.a += new System.EventHandler(z1);
//x.b += new System.EventHandler(z2);
//x.c += new System.EventHandler(z2);

//ORIGINAL LINE: Private Sub z1(sender As Object, e As
System.EventArgs) Handles x.a
private void z1(object sender, System.EventArgs e)
{
}
//ORIGINAL LINE: Private Function z2(sender As Object, e As
System.EventArgs) As Integer Handles x.b, x.c
private int z2(object sender, System.EventArgs e)
{
}
 

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

Similar Threads


Top