<VB.NET>自定义控件传递事件

Public Class Form1
    WithEvents TextBoxPluss As TextBox 'WithEvent一个TextBox控件,因为自定义控件中需要传递的事件为TextBox的事件

    Private Sub TextBoxPlus_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxPluss.KeyPress'定义一个KeyPress事件(其他事件也可以)
        MsgBox(e.KeyChar)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBoxPluss = TextBoxPlus1.TextBox1'在主窗体的Load事件中将自定义控件中的控件赋值给WithEvent出来的控件,使其在主窗体中有对象。
    End Sub
End Class

猜你喜欢

转载自blog.csdn.net/qq_18301257/article/details/79225049