且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将控件的多个实例动态添加到窗口窗体?

更新时间:2023-12-06 16:19:04

使用对用户控制对象的引用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.