如何添加另一个实例 [英] How to add another instance

查看:80
本文介绍了如何添加另一个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个名为PumpControl1的用户控件.如何将x的数量添加到frmMain表单中?我显然希望它们能够正确绘制,而不是彼此重叠.

谢谢,

Mike.

Hello,

I have a user control called PumpControl1. How can I add x number of these to my form frmMain? I obviously want them to be drawn correctly and not over one another.

thanks,

Mike.

推荐答案

Jibrohni写道:
Jibrohni wrote:

如何添加x个这样的数字到我的表格frmMain?

How can I add x number of these to my form frmMain?


例如,您可以添加PumpControl的数组作为该类的成员.



You may, for instance, add an array of PumpControl as member of the class.


Jibrohni写道:
Jibrohni wrote:

我显然希望它们能正确绘制而不是彼此重叠.

I obviously want them to be drawn correctly and not over one another.


这取决于您(即在将组件添加到表单时正确设置组件的位置和大小).
:)


This is up to you (i.e. set properly the position and size of the components when you add them to the form).
:)


PumpControl1 pc1A = new PumpControl1();
// position as required (you''re going to have to figure this out on 
// your own because we don''t know where you want them to be position.



根据需要重复,如下所示:



Repeat as necessary, like so:

PumpControl1 pc1B = new PumpControl1();



就像提到的 CPalinni CPallini一样,您可以将它们放入列表(甚至是字典,以便可以通过名称或数字ID或任何其他名称来引用它们).但是,如果要执行此操作,我将创建一个方法,该方法创建一个控件实例,然后将该实例添加到您的集合中.
[小心翼翼的约翰...在左边的手提箱里,我会找到我最喜欢的斧头. - Carlo ]



Like CPalinni CPallini mentioned, you could put them into a List (or even a Dictionary so you could refer to them by name or numeric ID, or whatever). If you''re going to do this, though, I would create a method that creates a single control instance and then adds that instance to your collection.
[Careful John... in the suitcase on the left I''ll find my favorite axe. - Carlo]


您可以使用数组或列表来存储控件,如先前答案中所建议的那样.

要显示它们,您可以使用TableLayoutPanel容器.动态添加ColumnStyle和RowStyle并将泵控件添加为
You can use an array or List to store the controls as suggested in the previous answers.

To display them you can use TableLayoutPanel container. Dynamically add ColumnStyle and RowStyle and add the pump control to a particular cell as
tblPanel.Controls.Add(new PumpControl(), 0, 0);





这样,您无需担心控件在窗体中的位置.如果控件的总数超过大小,也可以使TableLayoutPanel滚动.





By doing this you don''t need to worry about the location of the control in form. You can also make the TableLayoutPanel scrollable if the total number of your control exceed the size.


这篇关于如何添加另一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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