I have created a generic usercontrol like this:
public class MyControl<T>: TabControl
{
}
If T
was of primitive types, I would make my usercontrol non-generic and I would give an option to the user as a property to select the type, however T
can be any class type.
My usercontrol works perfectly when added programmatically, however, when I add it from toolbox there are 3 problems:
- When added shows a blank control (not a
TabControl
)
I Expect to see a normal TabControl and it has nothing with its being generic
- I have to go to Form.Designer.cs file and change its declarations to match the type I want
like:
private MyControl myControl1;
to
private MyControl<AClass> myControl1;
and
this. myControl1 = new MyControl();
to
this. myControl1 = new MyControl<AClass>();
I know that when control added it can not predict what the class would be, I'm not expecting some magic, but Is there a way that the user wouldn't need to go to the designer each time they add a control and somehow solve the problem with a property may be?
- After making changes in the Designer.cs the form designer shows errors and can not show the designer.
This one is on my nerves and why even having a generic declaration would cause error for designer (although when running the application it runs with no problem).