title: Delegate and AddressOf
body: <p>I have a problem I can not solve.</p>
  
  <p>I created a simple form with a for loop that deals with the creation of n buttons, at the end of the cycle i set to the button a specific sub for the .Click event</p>
  
  <pre><code>AddHandler btn.Click AddressOf mySub
  </code></pre>
  
  <p>now i want to do the same thing inside a class. So i created i new class then i wrote a simple method</p>
  
  <pre><code>Public Sub buttonCreation(byval nButton as Integer)
  </code></pre>
  
  <p>the method does exactly the same thing as the one in the form, but i stuck when i have to add the Handler for the .Click Event of the button.</p>
  
  <p>I then attempted to crare a delegate but I could not use it, AddressOf accepts only the NAME of the method without parentheses.</p>
  
  <p>EDIT </p>
  
  <p>i created the delegate inside the form</p>
  
  <pre><code> Dim delegate As EventHandler
   delegate  = New EventHandler(AddressOf mySub)
  </code></pre>
  
  <p>then i call my class method and pass delegate as parameter</p>
  
  <pre><code>ClassA.buttonCreation(10, delegate) 
  </code></pre>
  
  <p>I'm stuck here at the end of the cycle should be assigned to the sub button to invoke when the event. Click is fired, I tried to do this but obviously does not work</p>
  
  <pre><code>AddHandler btn.Click AddressOf delegate
  </code></pre>
  
  <p>Can you help me ? 
  Best Regards</p>
  
  <p>PS: obviously the method that I want to point is not inside the class, but it is inside the form.</p>