Abstract class, inheritance and designer

V

Vlado B.

Hello everyone!

Postoji li naèin da ovo bude ispravno i da se sve vidi u designeru?

Is this peace of code correct and if is, is there a way to see Form2 in
designer?

public abstract class Form1 : System.Windows.Forms.Form
{
....
protected abstract void Do();
....
}

public class Form2 : Form1
{
....
protected override void Do()
{
}
....
}

static void Main()
{
Application.Run(new Form2());
}

This works ok in runtime but if I want to see Form2 in designer I get this
error message:
The designer must create an instance of type 'Form1' but it cannot because
the type is declared as abstract.

TIA,

Vlado
 
H

Herfried K. Wagner [MVP]

* "Vlado B. said:
Is this peace of code correct and if is, is there a way to see Form2 in
designer?

public abstract class Form1 : System.Windows.Forms.Form
{
...
protected abstract void Do();
...
}

public class Form2 : Form1
{
...
protected override void Do()
{
}
...
}

static void Main()
{
Application.Run(new Form2());
}

This works ok in runtime but if I want to see Form2 in designer I get this
error message:
The designer must create an instance of type 'Form1' but it cannot because
the type is declared as abstract.

The designer will instantiate the base class, so you must not mark it as
'abstract'. That's a "limitation" of the designer.
 
V

Vlado B.

Herfried K. Wagner said:
The designer will instantiate the base class, so you must not mark it as
'abstract'. That's a "limitation" of the designer.


Thanks Herfried,

Is there some workaround for that limitation?

Also, I've made one more inheritance

public class Form3 : Form2
{
}

and Form3 is normally shown in the designer and that's a little bit strange
to me (still not expert).

AFAIK class's constructor calls constructor of base class, so why designer
works fine in this case?

Vlado
 
H

Herfried K. Wagner [MVP]

* "Vlado B. said:
Is there some workaround for that limitation?
No.

Also, I've made one more inheritance

public class Form3 : Form2
{
}

and Form3 is normally shown in the designer and that's a little bit strange
to me (still not expert).

You mean:

'Form1' (abstract)
'Form2' (not abstract)
'Form3' (not abstract)

The designer should work for 'Form3' because its base class is not
abstract.
 

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