Alexis Lestrange
Alexis Lestrange

Reputation: 347

How to use event handlers from a custom text box?

The question title may not be correct in this case, but I can't seem to find the answer to my problem any where else.

I have created a custom text box that is essentially a textbox within a panel within a user control. When I add this textbox to a form and want to use the eventhandlers from the textbox specifically, that is where things start to enter a grey area for me.

Upvotes: 2

Views: 289

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27342

You need to define the events you want to use inside your user control

For example if you want to fire the TextChanged event, when the TextChanged event of the textbox fires:

Public Class MyUserControl : Inherits Control

    Public Shadows Event TextChanged(sender As Object, e As EventArgs)

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        RaiseEvent TextChanged(sender, e)
    End Sub
End Class

Note that you need to declare it Shadows to avoid a conflict with the base class

Upvotes: 2

Related Questions