Abstract Classes and Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

using VS 2003

Is there a solution/work around

//the following, and all variations, creates a compile erro

abstract class MyAbstrac
{ ...

public class Foo : System.Windows.Forms.Form, MyAbstrac
{ ...

/
this doesn’t create a compile error but the “designer†hides the form and gives an informational error that basically says cannot create an instance of form. Application runs O’
*

abstract class MyAbstract: System.Windows.Forms.For
{ ...

public class Foo : MyAbstrac
{ ...
 
Steve said:
using VS 2003.

Is there a solution/work around?

//the following, and all variations, creates a compile error

abstract class MyAbstract
{ ... }

public class Foo : System.Windows.Forms.Form, MyAbstract
{ ... }

This gives an error because you can not inherit from multiple baseclasses
(it IS possible to implement multiple interfaces)
/*
this doesn't create a compile error but the "designer" hides the form and gives an informational error that basically says cannot
create an instance of form. Application runs O'K
*/

abstract class MyAbstract: System.Windows.Forms.Form
{ ... }

public class Foo : MyAbstract
{ ... }

This is a problem in VS, it apparently doesn't really like inherited forms.


Hans Kesting
 
gives an informational error that basically says cannot
create an instance of form. Application runs O'K

This is a problem in VS, it apparently doesn't really like inherited forms.


Hans Kesting


It can be done. You have to put the form you're inheriting from in a separate
DLL. The Add to Project wizard gives Inherit Form as one of the options
somewhere (I have done it once).
 
This seems to work. Don’t really need a interface though. The keyword Abstract seems to conflict with form class (maybe for good reason). The gang of 4 would call this a abstract factory pattern, I think..

interface MyInterfac
{ ...

public class XYZ : System.Windows.Forms.Form //bas
{ ...

public class ABC : XYZ, MyInterface //derive
{ ...

Stev
 
With all due respect to those that already answered...

There is nothing wrong with the designer. (in the case anyway)
You don't have to place the base class into a different DLL (you can place a
base of a form into the same DLL/EXE but you need to compile before the
designer will display the inherited form)

The designer will not show the form if it inherits from an abstract base
class.

Think of it this way; the designer needs to know how to construct the object
to display it, and if the base class is abstract, how can it do that?

As long as you inherit from an abstract base class there is no work around.

Brian W

Steve said:
using VS 2003.

Is there a solution/work around?

//the following, and all variations, creates a compile error

abstract class MyAbstract
{ ... }

public class Foo : System.Windows.Forms.Form, MyAbstract
{ ... }


/*
this doesn't create a compile error but the "designer" hides the form and
gives an informational error that basically says cannot create an instance
of form. Application runs O'K
 
Brian W said:
With all due respect to those that already answered...

There is nothing wrong with the designer. (in the case anyway)

I would dispute that, myself...
You don't have to place the base class into a different DLL (you can place a
base of a form into the same DLL/EXE but you need to compile before the
designer will display the inherited form)

The designer will not show the form if it inherits from an abstract base
class.

And *that's* what's wrong with it, IMO.
Think of it this way; the designer needs to know how to construct the object
to display it, and if the base class is abstract, how can it do that?

By constructing an instance of the concrete base class. It's not like
you're trying to design an abstract form - you're trying to design a
concrete form which happens to have an abstract base.
 
Just a try:
did you make a sibling constructor to the Form class constructor and called
the base constructor?

code:
public MyAbstractClass() : base()

I found that many times, when I inherit from controls, if I do not specify
this construction scheme, the designer would not show it...

Picho

Hans Kesting said:
This gives an error because you can not inherit from multiple baseclasses
(it IS possible to implement multiple interfaces)
and gives an informational error that basically says cannot
 
Back
Top