471,073 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

MustInherit and Design Mode

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
Nov 20 '05 #1
1 1432
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ray Cassick \(Home\) | last post: by
4 posts views Thread by Academia | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.