Events Demonstration - AddHandler : AddHandler « Event « VB.Net Tutorial






Events Demonstration - AddHandler
imports System
imports System.Drawing
imports System.Windows.Forms

public class EventsDemo : inherits System.Windows.Forms.Form

  Private btn as Button

  public sub New()
    btn = new Button()
    btn.Location = new Point(50,50)
    btn.Text = "Test"

    Controls.Add(btn)
        AddHandler btn.Click, AddressOf btn_Click
  end sub

  public shared sub Main() 
    Application.Run(new EventsDemo())
  end sub

  private sub btn_Click(ByVal sender as object,ByVal e as EventArgs)
    MessageBox.Show("btn_Click method","Events Demonstration")
  end sub
end class








11.2.AddHandler
11.2.1.Events Demonstration - AddHandlerEvents Demonstration - AddHandler
11.2.2.AddHandler btn.Click, AddressOf btn_ClickAddHandler btn.Click, AddressOf btn_Click
11.2.3.Add general to Label using AddHandler lblTitle.Click, AddressOf GenericEventAdd general to Label using AddHandler lblTitle.Click, AddressOf GenericEvent
11.2.4.Use AddHandler to add event handler to a buttonUse AddHandler to add event handler to a button
11.2.5.Static and Dynamic Events