MustInherit and Design Mode

  • Thread starter Thread starter Lance
  • Start date Start date
L

Lance

I get an exception when attempting to open a form in
design mode if the form inherits from a form that is
declared as MustInherit. For example, if I have:

Public MustInherit Class TestFormBase
Inherits Windows.Forms.Form
'...Normal Windows Form Designer generated code here
Public MustOverride Function GetValue() As Integer
End Class

Public Class TestForm
Inherits TestFormBase
'...Normal Windows Form Designer generated code here
Public Overrides Function GetValue() As Integer
Return 100
End Function
End Class

Then I get the following exception when I attempt to open
TestForm in design mode:

The designer must create an instance of
type 'TestFormBase' but it cannot because the type is
declared as abstract.

Curiously, I do not get an exception if I open
TestFormBase in the designer.

Is there any way to avoid this exception?

Thanks,
Lance
 
Lance,
Is there any way to avoid this exception?

I would do something like this

#If DEBUG Then
Public Class TestFormBase
#Else
Public MustInherit Class TestFormBase
#End If

#If DEBUG Then
Public Overridable Function GetValue() As Integer
Throw New NotImplementedException
End Function
#Else
Public MustOverride Function GetValue() As Integer
#End If



Mattias
 
Back
Top