Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top