2012-11-11 59 views

回答

0

UserControl中創建一個自定義事件,處理按鈕單擊並從中提起按鈕。然後,從父表單處理您的自定義事件UserControl。爲了說明這一點,這裏是一個代碼示例(VB.NET - 我不是在C#非常好):

Public Class UserControl1 
    Public Event ButtonClicked(tag As Object) 
    Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click 
    RaiseEvent ButtonClicked(CType(sender, Button).Tag) 
    End Sub 
End Class 

Public Class Form1 
    Private Sub UserControl11_ButtonClicked(tag As Object) Handles UserControl11.ButtonClicked 
    TextBox1.Text = tag 
    End Sub 
End Class 
相關問題