Abstract Base Forms do not display on Inherited form designer

  • Thread starter Thread starter Giovanni Bassi
  • Start date Start date
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
 
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.
 
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.
 
Back
Top