How to inherit the general form and open it in the designer of Visual Studio?

In my application, I have a BaseForm that has a common element in it:

 public partial class BaseForm<T> : Form where T : Presenter { protected T Presenter; public BaseForm() { InitializeComponent(); } } 

Now I need to have a form that is inherited from my BaseForm

 public partial class SampleForm : BaseForm<SamplePresenter> { public SampleForm() { InitializeComponent(); Presenter = new SamplePresenter(); } } 

The problem is that the Visual Studio designer is not showing my SampleForm retrieved from BaseForm<T> .

This is a warning:

Warning 1 A designer cannot be shown for this file, because none of the classes inside it can be designed. The designer checked the following classes in the file:

SampleForm --- The base class 'Invoice.BaseForm' cannot be loaded. Make sure that the assembly contains links and that all projects are built. 0 0

How can I overcome this?

PS I looked at this post , but I really did not understand the whole idea of โ€‹โ€‹how to solve this.

+7
generics inheritance c # visual-studio windows-forms-designer
source share
1 answer

The designer does not support this, as described in this article.

You need this base class:

 public partial class SampleFormIntermediate : BaseForm<SamplePresenter> { public SampleFormIntermediate() { InitializeComponent(); Presenter = new SamplePresenter(); } } 

And you need to use this class for the designer of Visual Studio:

 public partial class SampleForm : SampleFormIntermediate { } 

Thus, Visual Studio "understands" what to open in the designer and how to open it.

+10
source share

All Articles