0
Answer

Generic User Controls (C#)

Nicholas

Nicholas

16y
6.3k
1

I've seen people talking about generic user controls but I don't know how this would work. I can't find any examples of it either.

Basically what I want to do have a custom user control that contains a group box. The generic type would be some type of control or usercontrol. I would have something like... CustomListBox<TControlType> and then I want to be able to make a class like class TextboxListBox: CustomListBox<TextBox> or class ButtonListBox: CustomListBox<Button> and then when i create a instance of TextboxListBox in my form it would be a textbox inside of a group box. ButtonListBox would create a groupbox with a button inside.

And it's a CustonListBox because i want a .Add() function that creates a new <TControlType> and places it inside of the groupbox.

Does anyone know how this can be done? Or where there is an example how to make Generic User Controls?