Is there a more elegant way to do this? :

For Each ctrl As Control In Me.Controls
                If TypeOf ctrl Is txtBase Then
                    Dim ctrl1 As txtBase = ctrl
                    ctrl1.ioEnable(value)
                End If
                If TypeOf ctrl Is pnlBase Then
                    Dim ctrl1 As pnlBase = ctrl
                    ctrl1.ioEnable(value)
                End If
           Next

"Me" is a form. and txtBase and pnlBase are subclassed from textbox and panel respectively. Both the classes have .ioEnable method.

Ideally I would like to add an abstact (overridable) .ioEnable method to the Control class, so that I could code :

For Each ctrl As Control In Me.Controls
                       ctrl.ioEnable(value)
                   Next

If I then write a .ioEnable for my btnBase and my pgfBase, I would not have to worry about this anymore.

The best way is to create user contros that ineherits from the control base.

On the user controls you can add as many properties, functions and methods you need.

In this example you should create two user controls: one for text base and the other for the panel.

When defining the user control youput inside the original control to be expanded.
Then on the UserControl class, you can add properties and methods to manage the original control.

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.