Converting Custom Events from C# to VB.Net
-
Hi, I am writing this in hopes that someone out there can help me with the creation or a work around for how to write custom events in vb.net. eg. public event CustomEvent as Something { add { this.Pevent+=value ; } remove { this.Pevent-=value; } } All that I can do in vb.net seems to be Private event Pevent as SomethingHandler Public event CustomEvent as SomethingHandler I need this event to occur when the user clicks in a cell of a datagrid. It will addhander through a private function. But, I don't know if this is possible or how to do this in vb.net. Help please. Thank you. eatwork
-
Hi, I am writing this in hopes that someone out there can help me with the creation or a work around for how to write custom events in vb.net. eg. public event CustomEvent as Something { add { this.Pevent+=value ; } remove { this.Pevent-=value; } } All that I can do in vb.net seems to be Private event Pevent as SomethingHandler Public event CustomEvent as SomethingHandler I need this event to occur when the user clicks in a cell of a datagrid. It will addhander through a private function. But, I don't know if this is possible or how to do this in vb.net. Help please. Thank you. eatwork
Something like this (obtained with Instant VB after adding a delegate declaration): Public Delegate Sub Something(ByVal sender As Object, ByVal e As System.EventArgs) Public Custom Event CustomEvent As Something AddHandler(ByVal value As Something) AddHandler Me.Pevent, value End AddHandler RemoveHandler(ByVal value As Something) RemoveHandler Me.Pevent, value End RemoveHandler RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs) End RaiseEvent End Event David Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C# to C++ converter and VB to C++ converter Instant J#: VB to J# converter Clear VB: Cleans up VB.NET code Clear C#: Cleans up C# code
-
Something like this (obtained with Instant VB after adding a delegate declaration): Public Delegate Sub Something(ByVal sender As Object, ByVal e As System.EventArgs) Public Custom Event CustomEvent As Something AddHandler(ByVal value As Something) AddHandler Me.Pevent, value End AddHandler RemoveHandler(ByVal value As Something) RemoveHandler Me.Pevent, value End RemoveHandler RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs) End RaiseEvent End Event David Anton www.tangiblesoftwaresolutions.com Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: C# to C++ converter and VB to C++ converter Instant J#: VB to J# converter Clear VB: Cleans up VB.NET code Clear C#: Cleans up C# code
-
Hi David, Thank you for your response and solution. I will give that a try, but it looks like it should work. Thank you. eatwork
There is an even better way to do this now in Visual Basic for .NET 4.0: Here is a perfect example of using Visual Basic's Custom Event which also includes new multi-line Lamda's which were available in C# and not VB. I switched to C# since it always seemed ahead of VB and have been really happy yet with .NET, you can always mix and match so can still use things like VB's inline XML for parts of your solution. What is disturbing to me though is that the more I learn about non-Microsoft languages, the more I find out that a lot of this stuff has been done before. Now I just try to learn everything which is impossible and has caused me to go Col. Walter E. Kurtz... The Horror, The Horror... Here is the link to Bill Wagner's amazing code(It's topic is Tuples feature yet there is a rework of his October 2009 article code using Custom Event, Tuples, and Multi-Line Lamda's that is a perfect example of what you can do and shows what you wanted as well): :sigh: :)
-
Hi, I am writing this in hopes that someone out there can help me with the creation or a work around for how to write custom events in vb.net. eg. public event CustomEvent as Something { add { this.Pevent+=value ; } remove { this.Pevent-=value; } } All that I can do in vb.net seems to be Private event Pevent as SomethingHandler Public event CustomEvent as SomethingHandler I need this event to occur when the user clicks in a cell of a datagrid. It will addhander through a private function. But, I don't know if this is possible or how to do this in vb.net. Help please. Thank you. eatwork