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
答案 0 :(得分:3)
您正在混合使用C#和VB.Net代码。
mrButton.Click += New system.EventHandler(MyButtonClickEventHandler)
是C#语法。
按钮处理程序应声明为:
Private Sub MyButtonClickEventHandler(ByVal sender As Object, ByVal e As EventArgs) Handles mrButton.Click
或者您使用AddHandler
作为:
AddHandler mrButton.Click, AddressOf MyButtonClickEventHandler