Abstract Base Forms do not display on Inherited form designer

G

Giovanni Bassi

Hello All,

I am working with visual inheritance and I would like my base form to be
abstract (MustInherit). If I do so, I can't use the designer window on the
inherited form anymore. It displays this error:

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

I need to use the MustInherit Keyword to be able to use the MustOverride
Keyword on my operations. Some of these operations *need* to be overriden.

How do I do that? How can I conciliate an abstract base form with a designer
on the inherited form?

Thanks a lot for all replies!

Giovanni Bassi
 
H

Herfried K. Wagner [MVP]

Giovanni Bassi said:
I am working with visual inheritance and I would like my base form to be
abstract (MustInherit). If I do so, I can't use the designer window on the
inherited form anymore. It displays this error:

That's a limitation of the Windows Forms designer. You must not mark
the classes as 'MustInherit' in order to use them with the designer.
 
K

kam

I ran into this too, and fortunatly found the answer
posted. I am writing it for C#, just convert for VB.

Go to your base class and put a #if DEBUG ... #else ...
#endif around the lines with abstract. In the #if
section, copy the line but remove the abstract keyword,
like so:

#if DEBUG
public class YourControl:
System.Windows.Forms.UserControl
#else
abstract public class YourControl:
System.Windows.Forms.UserControl
#endif


If you have abstract member functions, then again make a
copy and change the #if section to be virtual functions,
like so:
#if DEBUG
virtual protected void funct()
{
throw new NotImplementedException();
}
#else
abstract protected void func();
#endif


Hope this helps.
 

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