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.
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.
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.
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.
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.
Could this be a help to you?
How to Clone/Serialize/Copy & Paste a Windows Forms Control
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With