Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone Winform control

I have a groupox in a VB.NET winform app. The groupbox contains a few Labels, Textboxes and Checkboxes. This was created by simply dragging the controls out of VS toolbox.

What I need to do is take the 1 Groupbox and at runtime create multiple Groupboxes to display based on user selection. Instead of dynamically creating the Groupboxes and other controls nested inside, is there a way to clone or copy the original one.

Then I'd just change the properties. Label text, Textbox text, etc. And the location of the Groupbox in the layout.

like image 972
rioja Avatar asked Feb 04 '10 16:02

rioja


People also ask

How do I copy a winform file?

Press "Ctrl" and drag your mouse to duplicate a existing form class file. Then exlude the existing form class file from the project. Rename the new form class file.

How do I copy WinForms from one project to another?

Add the project from which you want to import form to your solution, by right clicking on solution > Add > Existing project menus. Select the project and click OK. Now right click on the form you want to copy, select copy. Right click on the project where you want to copy and select paste.

Is winform still used?

As we mentioned above, WinForms is still available but the status of “maintenance mode” likely means it has no long term future. As time passed by, especially in the last 5-10 years, new tools continued to mature and rise in popularity, and each one of them offered many powerful features.


2 Answers

What you could do is create a user control based upon your groupbox which would allow its reuse. You could then create the instances you require at runtime and add them to the form.

Maybe suggest that you look into creating user controls for winforms.

like image 149
David Avatar answered Nov 15 '22 04:11

David


Could this be a help to you?
How to Clone/Serialize/Copy & Paste a Windows Forms Control

like image 43
Tun Avatar answered Nov 15 '22 04:11

Tun