Clone Winform control

风格不统一 提交于 2019-12-19 07:49:19

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2201341/clone-winform-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!