如何将控件的多个实例动态添加到窗口窗体? [英] How to add Multiple Instances of a control dynamically to a Window-Form?
本文介绍了如何将控件的多个实例动态添加到窗口窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个包含单选按钮,文本框,标签等的用户控件.
我想将此控件添加到单击按钮的窗口窗体中.我可以多次添加此控件.
如何动态创建其实例?
在此先感谢.
Hi,
I have created a user-control containing radio-buttons,text-box,labels etc.
I want to add this control to window-Form on button click. I can add this control many times.
How Can i create its instances dynamically?
Thanks in Advance.
推荐答案
使用对用户控制对象的引用List<T>
.每次单击该按钮时,将创建这些对象的新实例,并将引用添加到列表中.对象的构造函数应包含初始化组件的所有必要步骤.您还可以添加一个参数来分配当前对象的列表索引.
Use a List<T>
of references to your user-control objects. Each time the button is clicked create a new instance of these objects and add the reference to your list. The object''s constructor should contain all necessary steps to initialize the components. You could also add a parameter to assign the List''s index of the current object.
这篇关于如何将控件的多个实例动态添加到窗口窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文