Creating custom controls with generics

We want to create a custom WinForms control (which is derived from a .net control) and be able to drag it out of the tool window in the designer view. However, we cannot do this when we have a generic control, because when a designer tries to instantiate a class, for obvious reasons he doesn't know what type the instance should be.

Does anyone know about this?

Thank you in advance

====== edit ===========

What we would like to do is an example:

public class MyDataGridView<T> : DataGridView where T : class{
...
}

      

by removing the generics, we can see the preview in the designer as if it were a regular DataGridView, but as I explained above with generics, we cannot use the constructor.

+3


source to share


1 answer


I faced the same problem and the result was this: Don't use shared controls in designer view! You can create instances programmatically, but you don't have a preview. Perhaps it works when you add a derived class that explicitly sets a common parameter.



+3


source







All Articles