Reputation: 14787
I have been using form inheritance for a while now but without doing much research with the following approach. Simply create a new class instead of a form and inherit from an existing form and convert required controls to protected as needed. Visual Studio 2010 designer works like a charm. If more control is required, you can always override base methods.
I am now creating generic forms as follows:
partial class EntityCollectionEditor < T > : Form where T : ISomeInterface < T >
Forms such as this when inherited by simple non-designer classes give the following error:
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: XYZ. The base class EntityCollectionEditor could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
A quick solution would be nice but I'm also looking for a good resource/article to educate myself.
Upvotes: 2
Views: 845
Reputation: 11617
Currently, the winforms designer does not support generic forms/controls.
The only work around I have used is to create a specific form type:
class GenericBaseForm<T> : Form
{ }
class IntForm : GenericBaseForm<Int>
{ }
class StringForm : GenericBaseForm<String>
{ }
The specific forms can now be used in the designer. Unfortunatly, if you have a lot of specific forms, its probably not an ideal solution.
Upvotes: 3