locked
delegate vb.net equivalent RRS feed

  • Question

  • Hi

    What is the vb.net equivalent of this statement please?

        item.ControlCreated += delegate(object sender, EventArgs e) {
    
        };

    Thanks

    Regards


    • Edited by Y a h y a Wednesday, October 9, 2013 12:13 AM
    Wednesday, October 9, 2013 12:12 AM

Answers

  • Try this demo:

     Dim a As New TryAnonymousClass
     AddHandler a.CreatedAddressOf MyFun
    Private Sub MyFun(sender As Objecte As EventArgs)
            'Your method here
    End Sub

    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    • Edited by ThankfulHeart Wednesday, October 9, 2013 12:43 AM Modify
    • Marked as answer by Carl Cai Thursday, October 17, 2013 1:29 AM
    Wednesday, October 9, 2013 12:36 AM
  • With VS 2010 or newer, you can just use a 'Sub' lambda:

    	AddHandler item.ControlCreated, Sub(sender As Object, e As EventArgs)
    
    	End Sub


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    • Proposed as answer by ThankfulHeart Wednesday, October 9, 2013 1:55 AM
    • Marked as answer by Carl Cai Thursday, October 17, 2013 1:29 AM
    Wednesday, October 9, 2013 1:13 AM

All replies

  • Try this demo:

     Dim a As New TryAnonymousClass
     AddHandler a.CreatedAddressOf MyFun
    Private Sub MyFun(sender As Objecte As EventArgs)
            'Your method here
    End Sub

    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    • Edited by ThankfulHeart Wednesday, October 9, 2013 12:43 AM Modify
    • Marked as answer by Carl Cai Thursday, October 17, 2013 1:29 AM
    Wednesday, October 9, 2013 12:36 AM
  • Why don't you try using Teleriks on line code converter rather than asking for others to convert your code for you?

    This is a conversion of the code you posted using Teleriks converter.

    item.ControlCreated += Sub(sender As Object, e As EventArgs) 
    
    End Sub
    


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Wednesday, October 9, 2013 1:12 AM
  • With VS 2010 or newer, you can just use a 'Sub' lambda:

    	AddHandler item.ControlCreated, Sub(sender As Object, e As EventArgs)
    
    	End Sub


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    • Proposed as answer by ThankfulHeart Wednesday, October 9, 2013 1:55 AM
    • Marked as answer by Carl Cai Thursday, October 17, 2013 1:29 AM
    Wednesday, October 9, 2013 1:13 AM
  • item.ControlCreated += Sub(sender As Object, e As EventArgs) 
    End Sub

    Hello Mr.MonkeyBoy:

    But I'm afraid this isn't right……in vb.net, "+=" isn't supported for handling an event.


    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    Wednesday, October 9, 2013 1:20 AM