views:

22

answers:

1
Imports System
Imports System.Windows.Forms
Class MyButtonClass
    Inherits Form

    Private mrButton As Button
    Public Sub MyButtonClass()

        mrButton = New Button()
        mrButton.Text = "Click me "
        mrButton.Click += New System.EventHandler(MyButtonClickEventHandler)
        Me.Controls.Add(mrButton)
    End Sub
    Shared Sub Main()
        Application.Run(New MyButtonClass())
    End Sub
    Private Sub MyButtonClickEventHandler(ByVal sender As Object, ByVal e As EventArgs)
        mrButton.Text = "You clicked me!"
    End Sub
End Class
+2  A: 

You're mixing C# and VB.Net code.

mrButton.Click += New system.EventHandler(MyButtonClickEventHandler)

Is C# syntax.

The button handler should either be declared as:

Private Sub MyButtonClickEventHandler(ByVal sender As Object, ByVal e As EventArgs) Handles mrButton.Click

Or you use the AddHandler as:

AddHandler mrButton.Click, AddressOf MyButtonClickEventHandler
ho1