2010-06-13 23 views
0
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 
+1

格式化代碼,在編輯器中按Ctrl-K選擇它。另一方面,不要只發布一堆代碼,並期望有人在這裏爲你解決所有的問題。你甚至不會說你看到了什麼錯誤! – 2010-06-13 09:31:33

+0

Mr Button。我不記得他從[系列](http://en.wikipedia.org/wiki/Mr._Men) – 2010-06-13 10:06:50

+0

將從現在開始做它,我是新來的它會學習,而我不在這裏人們會解決我所有的問題 – Rishabh 2010-06-14 16:40:55

回答

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