Inheritance cannot be shown in the designer

Today I am facing a problem. Properly.
I create a general form,
Public class Form1: Form
Then I create another form of inheritance,
Public class From2: Form1.
Form 2 cannot be shown in the VS constructor, the error message "all classes in the file cannot be developed" (this error message is translated from Chinese, the Chinese message is ๆ–‡ไปถ ไธญ ็š„ ็ฑป ้ƒฝ ไธ่ƒฝ ่ฟ›่กŒ ่ฎพ่ฎก). <b> "But this program can be compiled successfully, and when it works, both Form1 and From2 can work.

Can anybody help me? Thanks.

I am not a native speaker of English. Hope I described my question clearly.

+1
generics inheritance visual-studio winforms
source share
2 answers

This is a limitation with the designer. You can get around this by adding an intermediate derived form that defines types. I explained this in a blog post:

http://adamhouldsworth.blogspot.com/2010/02/winforms-visual-inheritance-limitations.html

+6
source share

I wanted to give a more specific answer as a complement to Adam's message .

BaseForm is the name of your generic form; GenericClass one of the possible type parameters.

BaseForm<T> might look like this:

 public class BaseForm<T> : Form { } 

First you need a base class. This is actually the part that you probably already used before you came across this issue.

Then you use this intermediate implementation.

 public class SampleFormIntermediate : BaseForm<GenericClass> { public SampleFormIntermediate() { InitializeComponent(); } } 

And you need to use this class for the designer of Visual Studio. And only that. I would recommend decorating this with the compiler directive, so it will only be used in Debug mode:

 public partial class SampleForm : SampleFormIntermediate { } 

Using this Visual Studio "understands" what to open in the designer and how to open it.

+2
source share

All Articles