Designer cannot open a derivation from an abstract class

G

Guest

I am trying to build (in the .NET IDE and using VB) an app that uses forms I
am deriving from a base class which contains some functions declared as
'mustoverride' and the base class declared 'mustinherit'. The base class
inherits windows.forms. I get an error message telling me that the designer
cannot open the derived classes because the base is abstract. It seems such a
basic requirement of mine that I can hardly believe this is true. It means
that I can't do any visual design on the derived forms. Does anyone know a
way around this or am I missing something? Thanks if you can help,
Nigel Barton
 
H

Herfried K. Wagner [MVP]

Nigel,

Nigel B said:
I am trying to build (in the .NET IDE and using VB) an app that uses forms
I
am deriving from a base class which contains some functions declared as
'mustoverride' and the base class declared 'mustinherit'. The base class
inherits windows.forms. I get an error message telling me that the
designer
cannot open the derived classes because the base is abstract. It seems
such a
basic requirement of mine that I can hardly believe this is true. It means
that I can't do any visual design on the derived forms. Does anyone know
a
way around this or am I missing something?

That's a known limitation of the designer. You can partially work around it
by using this code:

\\\

' In the project properties the checkbox that defines the
' 'DEBUG' constant must be checked.
#If DEBUG Then
Public Class Foo
#Else
Public MustInherit Class Foo
#End If
...
End Class
///

In release mode the class will be 'MustInherit'.
 
G

Guest

Hi Herfried,

Thanks for you speedy reply. I can't say I have been successful with your
suggestion. Once the project has recognized that the base is abstract (you
can do quite a bit of work before it decides it doesn't want you to use the
designer on the abstract class anymore) it won't let go of the fact that the
base is abstract. I find, even if I remove the 'mustinherit' and any
'mustoverrides' from the base class the same error message appears on trying
to use the designer to open any derived classes - ie, that the class is
abstract. Thanks anyway,
 
G

Guest

Hi Nigel,

The way the designer works is by instantiating your base class and hosting
that in the designer. You can see this at work if you debug visual studio and
put a breakpoint in the constructor of your base class - it will be hit when
you bring up the subclass in the designer, however the constructor of that
subclass doesn't get called. That's why you can design abstract forms, but
can't design forms where the direct superclass is abstract.

Hope that helps.

Regards,
Matt Garven
 
B

Bruce Wood

Are you sure that you rebuilt the project? Closed the open form's
designer window and reopened it?

Yes, VS cannot design a form derived from an abstract base class. No,
it doesn't get "stuck," as such: you have to close the design view
(window), rebuild the project, and reopen it again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top