chuawenching Posted July 26, 2003 Posted July 26, 2003 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 Quote
*Experts* Volte Posted July 26, 2003 *Experts* Posted July 26, 2003 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. Quote
chuawenching Posted July 26, 2003 Author Posted July 26, 2003 ok thanks... I had looked into some of them... but i am trying my best to relate it... Anyway thanks for the reply.. Regards, Chua Wen Ching :p Quote
JABE Posted August 1, 2003 Posted August 1, 2003 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...> Quote
chuawenching Posted August 1, 2003 Author Posted August 1, 2003 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 Quote
JABE Posted August 1, 2003 Posted August 1, 2003 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. Quote
csharpener Posted August 12, 2003 Posted August 12, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.