Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# .NET: How to design a template and multiply it in a form

Here is a picture of what I'm trying to say:

You can see in the picture that I want to make a template and multiply it in my application. I came up with an idea that put the controls in a panel and multiply the panel with code, but the constructor of the panel wouldn't allow me to do that. Is there any other way I can multiply it cause I can't drag and drop all the controls into the form? Thank you in advance.

like image 852
123iamking Avatar asked Sep 03 '25 13:09

123iamking


1 Answers

You can create a UserControl and draw your Template inside the UserControl.

Then on the MainForm, you can use a LayoutPanel and dynamically instantiate your UserControl and add it to the Controls Collection of the LayoutPanel.

Step1 Create a new UserControl(say ucTemplate), and add the picture box & labels in it.

Step2 In the Main Form: Add a new LayoutPanel(or a simple Panel.

And whenever you want to repeat your template, simply call the addTemplate() method.

Public sub addTemplate()
    Dim ucTemplate = new ucTemplate()
    ucTemplate.Dock = Dock.Top

    LayoutPanel1.Controls.add(ucTemplate)
End sub
like image 89
Anshuman Chatterjee Avatar answered Sep 05 '25 15:09

Anshuman Chatterjee