Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# event += delegate {} equivalent in VB.NET

Well, I was translating a C# into VB.NET using developer fusion, and the API didn't translated me that part...

owner.IsVisibleChanged += delegate
            {
                if (owner.IsVisible)
                {
                    Owner = owner;
                    Show();
                }
            };

I know that += is for AddHandler owner.IsVisibleChanged, AdressOf (delegate??), so, which is the equivalent for that part?

Thanks in advance.

PD: I don't enough money for buy .NET Reflector :( And I wasted the trial.

like image 833
z3nth10n Avatar asked Feb 14 '23 03:02

z3nth10n


1 Answers

There are two parts here.

  1. Anonymous methods. delegate in C# roughly corresponds to an anonymous Sub in VB here.

  2. Adding event handlers. += in C#, AddHandler in VB.

Putting it together:

AddHandler owner.IsVisibleChanged, _
    Sub()
        …
    End Sub

Incidentally, the AddressOf operator you’ve mentioned is used in VB to refer to a (non-anonymous) method without calling it. So you would use it here if you would refer to an existing, named method rather than an anonymous method.

like image 129
Konrad Rudolph Avatar answered Feb 15 '23 16:02

Konrad Rudolph