4

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.

z3nth10n
  • 2,341
  • 2
  • 25
  • 49
  • There are free decompilers also. [Jetbrains DotPeek](http://www.jetbrains.com/decompiler/) and [ILSpy](http://ilspy.net/) for example.. – Soner Gönül Apr 26 '14 at 11:02
  • Wait, are you translating code into C# (like your question says), or into VB.NET (like your question title says)? –  Apr 26 '14 at 11:10
  • Sorry, I misstyped it, I'm translating C# into VB.NET – z3nth10n Apr 26 '14 at 11:10
  • Then please see [this other question](http://stackoverflow.com/q/10178159/743382). Despite the fact that the answer there is not accepted, I believe it is correct and also answers your question. –  Apr 26 '14 at 11:17
  • For those people that wants more reputation (up votes) check my new question: http://stackoverflow.com/questions/23310308/value-of-type-typename1-cannot-be-converted-to-typename2-using-a-structu – z3nth10n Apr 26 '14 at 11:39
  • @user3286975 The one titled "value-of-type-typename1-cannot-be-converted-to-typename2-using-a-struct" but which you have now removed? – ClickRick Apr 26 '14 at 13:07
  • I solved it, it was only a bad sensitive case mathod problem... – z3nth10n Apr 26 '14 at 14:17

1 Answers1

8

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.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214