克隆 Winform 控件 [英] Clone Winform control

查看:82
本文介绍了克隆 Winform 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VB.NET winform 应用程序中有一个 groupox.组框包含一些标签、文本框和复选框.这是通过简单地将控件拖出 VS 工具箱来创建的.

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.

我需要做的是获取 1 个 Groupbox 并在运行时创建多个 Groupbox 以根据用户选择显示.除了动态创建嵌套在其中的 Groupbox 和其他控件之外,有没有一种方法可以克隆或复制原始控件.

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.

那我就改变一下属性.标签文本、Textbox文本等以及Groupbox在布局中的位置.

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

推荐答案

你可以做的是基于你的 groupbox 创建一个用户控件,它允许它重用.然后,您可以在运行时创建所需的实例并将它们添加到表单中.

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.

也许建议您考虑为 winforms 创建用户控件.

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

这篇关于克隆 Winform 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆