-1
我有用戶控件的FormStart和我需要的NumericKeyPad,當我點擊按鈕例如按鈕3(帶標記值:3)在Formstart textBoxEmployee#上寫3等......如何處理用戶控件按鈕單擊事件父窗體
我有用戶控件的FormStart和我需要的NumericKeyPad,當我點擊按鈕例如按鈕3(帶標記值:3)在Formstart textBoxEmployee#上寫3等......如何處理用戶控件按鈕單擊事件父窗體
在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
那你試試? – kleopatra