I'd support nobugz
's answer. Even if there was an #Include
statement, I don't think that would be a good idea. Any change in the include file might easily break any of your 8 subclassed user controls.
BUT: What just might work, if all of the common changes can be integrated into the subclassed user controls via event handlers, or if the changes are of the type where you set common properties of your user controls to particular values, is a class that applies the code changes to any user control passed to it:
Class CommonChanges
Private Readonly WithEvents DerivedUserControl As Windows.Forms.Control
Public Sub New(ByVal derivedUserControl As Windows.Forms.Control)
Me.DerivedUserControl = derivedUserControl
End Sub
Private Sub DerivedUserControl_OnClick(sender As Object, e As EventArgs) _
Handles DerivedUserControl.Click
' ... '
End Sub
... ' (more event handlers with common code go here) '
End Class
Then, you define your 8 customized user controls like:
Class MyDerivedUserControl
Extends Button ' (or whatever control it extends) '
Private ReadOnly Changes As CommonChanges
Public Sub New
Changes = New CommonChanges(Me)
' ^ 'CommonChanges' will subscribe to this class's events and possibly
' apply other changes to the control object 'Me'.
...
End Sub
End Class
That object Changes
of type CommonChanges
will subscribe to events of your MyDerivedUserControl
class and hook the handlers defined in CommonChanges
to them.
Also, you can directly apply changes to the Control
object passed to CommonChanges
's constructor this way.