Search code examples
c#.netvisual-studio-2010window

C# Window Form Application, how to efficiently create a dynamic panel on a window form


I would like to create a few panel dynamically in my window form application. Each panel will consist of 3 labels and one text box and one button. Now I know I can hard code this all at once by declaring each variable every time, but it takes a lot of coding and it is obviously not efficient at all. So my question is: Is there a way to create pre-define panel dynamically where each time a panel is created will have a predefined layout setup already. So all i need to do is to add a panel, its location and size every time, and all the content(like labels, text-box and button) inside the panel are already setup with their location associated with the panel itself. Do I really have to create a class just for that?

Thanks in advance for read and taking your time.


Solution

  • Create Windows Forms control or user control, see http://msdn.microsoft.com/en-us/library/6hws6h2t.aspx