Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Converting Custom Events from C# to VB.Net

Converting Custom Events from C# to VB.Net

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eatwork
    wrote on last edited by
    #1

    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

    D M 2 Replies Last reply
    0
    • E 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

      D Offline
      D Offline
      Dave Doknjas
      wrote on last edited by
      #2

      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

      E 1 Reply Last reply
      0
      • D Dave Doknjas

        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

        E Offline
        E Offline
        eatwork
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • E eatwork

          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

          M Offline
          M Offline
          Michael J Apostol
          wrote on last edited by
          #4

          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: :)

          1 Reply Last reply
          0
          • E 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

            M Offline
            M Offline
            Michael J Apostol
            wrote on last edited by
            #5

            http://visualstudiomagazine.com/articles/2009/12/01/types-and-tuples-in-net-4.aspx[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups