JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Adding Events to User Controls

You can add an event to a user control as you would to any class; all you have to do is to declare the event and the parameters passed to the event's handler procedure.

Here's how that looked in the UserControls example discussed in the In Depth section of this chapter, where we declared an event named TextModified:

    Public Event TextModified(ByVal NewText As String)

This event occurs when the text displayed in the user control in this example is modified. In the UserControls example, we made this event happen when the SetText method (see the previous topic) was called, using the RaiseEvent method:

    Public Sub SetText(ByVal NewText As String)
        Label1.Text = NewText
        RaiseEvent TextModified(NewText)
    End Sub

That's all it takes. See the In Depth section of this chapter for more details on the UserControls example.

Related solution:

Found on page:

Creating Events


Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor