Hacer que las ventanas sean genéricas

One year after a similare question has been posted on SO. Generic Windows Form Template

Do you know if there're a better way to make a windows form generic, here's what I'd like to do:

public partial class EntryPointEditForm<T>  : Form where T : ICriteriaObject<T>

But an error is thrown telling me that: no suitable method found to override
en el método:

protected override void Dispose(bool disposing)

preguntado el 31 de julio de 12 a las 15:07

@AdamHouldsworth: I believe you are correct, but your reason is wrong. The designer does not need to do anything with the generic parameter; the designer only works with the base class. -

@Slaks My understanding (although my memory is hazy on it, it was a while ago) was that the design tries to instantiate the class being designed, but cannot because it has no T, hence resolving T to a strong type by using an interim seems to work. -

@AdamHouldsworth: No. The designer instantiates the base class, then explicitly reads the contents of the InitializeComponent method. This is why you can design an abstract form class. -

@Slaks I get you, and I've just re-read my post about it and came to the same conclusion. I even said as much in my post lol, just shows how useless my memory is on this particular topic - must be the reason I wrote it all down. -

Managed to delete the comment with my post link in it. Seguí leyendo. -

1 Respuestas

You need to change the partial class declaration in the .Designer.cs file to also be generic.

However, I don't think that the VS designer supports generic form classes.
You may need to make a non-generic abstract form to use with the designer, then make a generic class that inherits from it for you to actually use.

Respondido 31 Jul 12, 15:07

Thanks, it works. I will vote your question as accepted in 11min. - John

@JohnSmith: Did the designer work with the generic class, or did you need to apply my workaround? - SLaks

Give me 2sec, I try to load the designer. - John

@Slaks In this instance, unless EntryPointEditForm<T> is used as a base class there should be no problem. - adam houldsworth

The designer is loading fine using generic class. - John

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.