How do I create a handler for a inherited control in VB.NET?

Although VB .NET's WithEvents can be "handier" than C#'s event handler creation, this is one of those cases where it's not. Normally, to create an event handler you select a control from the top-left combo box in the Visual Studio IDE and select the event to handle in the top-right combo box. However, if the control is inherited from the base form it doesn't show up in this list. For inherited controls, you must manually create the event handler in VB .NET. For example, to create an event handler for an inherited TabControl, you can add a handler method to your form like this:


Private Sub TabControl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

End Sub

Then in your form's constructor, add code that registers the event handler with the associated event. For example:

AddHandler TabControl.SelectedIndexChanged, AddressOf Me.TabControl_SelectedIndexChanged


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 01/05/10
Comment or report problem with topic