Option Strict On
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1 : Inherits Form
Private WithEvents cmdClickCtr As Button = New Button()
Public Sub New()
Me.cmdClickCtr.Location = New Point(100, 75)
Me.cmdClickCtr.Size = New Size(100, 50)
Me.cmdClickCtr.Text = "Click Counter"
Me.Controls.Add(cmdClickCtr)
Me.Text = "Click Counter"
End Sub
Private Sub cmdClickCtr_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cmdClickCtr.Click
Static ctr As Integer = 1
MsgBox("Button was clicked " & ctr & " times.")
ctr += 1
End Sub
Public Shared Sub Main()
Dim frm As New Form1()
frm.ShowDialog()
End Sub
End Class