Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi there.

 

I search google that i can use delegate and events to replace WithEvents.. but i had 1 vb6 sample code.. which i not sure how to code it in c#

 

Code:

====

private WithEvents ParA as EngineParSystem

 

private Sub ParA_NewPar(VelocX as Single, VelocY as Single, VelocZ as Single)

 

LifeS = CurrentLifeT

 

End Sub

 

So how to code delegates and event with that in c#?

 

Any help?

 

Thanks.

 

Regards,

Chua Wen Ching :p

  • *Experts*
Posted

There is no equivilant in C#, since you need to manually add the handler anyway. You'll also need to create a custom EventHandler and EventArgs class and delegate.

 

Look for information on event handling on C# for more information.

Posted

Your VB.NET sample is quite incomplete:

 

private WithEvents ParA as EngineParSystem

private Sub ParA_NewPar(VelocX as Single, VelocY as Single, VelocZ as Single) [b] Handles ParA.SomeEvent[/b]

LifeS = CurrentLifeT

End Sub

 

As VolteFace has stated, WithEvents has no direct equivalent in C#. Translated to C#, your code will look something like this:

 

EngineParSystem ParA;

...

ParA.SomeEvent += new System.EventHandler(ParA_NewPar);

 

<ParA_NewPar sub somewhere...>

Posted

oh thanks...

 

Just wondering, i had a library created in vb.net, instead of converting it into c#, can i just load the entire library source code, and call it directly into c#.

 

I never try before, but i heard it can right?

 

Regards,

Chua Wen Ching :p

Posted
It's not possible to mix up .vb and .cs code files in one project. What's possible is compiling the vb component and using it in C#, or the other way around. Google ".NET code converters" if you need help in converting codes.
  • 2 weeks later...
Posted

dunno if this helps... here is what I have used

 

...first create a delegate...

 

public class ClassName

 

public ClassName()

{

public delegate void PlusButtonClickEventHandler(object sender, System.EventArgs e);

 

//define the event...

 

public event PlusButtonClickEventHandler PlusButtonClick;

 

}

 

// within the class you are referencing the control/class add

// an event constructor...

 

...

 

public class SomeOtherClass : System.Windows.Forms.Form

 

public SomeOtherClass()

{

 

this.form.PlusButtonClick += new ClassName.PlusButtonClickEventHandler(Function_Name);

 

 

// then add the function

 

 

private void Function_Name(object sender, System.EventArgs e)

{

//do stuff;

}

 

}

 

CS

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...