VB 2005: Don’t declare a form MustInherit if you will be inheriting the form

If you create a form to be inherited and you try to declare a function or procedure as MustOverride:

    Protected MustOverride Function MyFunction() As String

you need to declare that form MustInherit:

    Public MustInherit Class MyForm

But doing this will prevent you from inheriting the form because you won’t see this form on the Inheritance Picker tool window when you create an inherited form (Add New Item… -> Inherited Form).

You have no choice but to declare  your function or procedure as Overridable:

    Protected Overridable Function MyFunction()As String
        ' You can put some code here or nothing at all...
    End Function

and then make sure your derived form overrides this function:

    Protected Overrides Function MyFunction()As String
        ' Your code here...
    End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s