创建一组非标准控件 [英] Create an array of non standard controls
问题描述
大家好,
我正在使用Windows应用程序,所以我想知道创建一组非标准控件。就像我在我的应用程序中添加了一个自定义控件(用户控件),它的倍数是必需的。所需的控制权不是动态的。和其他标准控件一样,我们有类似的东西:
标签[]标签;
如何实现自定义控件?如果我以类似的方式做到这一点我得到一个错误说:控件丢失(你使用指令或程序集参考)
提前谢谢。
MyControl [] myControls = new MyControl [ 100 ];
但您可能需要使用添加如果控件位于不同的命名空间中,则声明到文件顶部。
使用 NamespaceHoldingMyControl;
如果它在不同的程序集中,例如DLL文件,那么你必须在项目中添加一个Reference,并使用line。
请尝试以下代码
private void Form1_Activated( object sender,EventArgs e)
{
Label [] lblTest = new 标签[ 5 ];
for ( int i = 0 ; i< 5; i ++)
{
lblTest [i] = new Label();
lblTest [i] .Name = lblTest + i.ToString();
lblTest [i] .Location = new System.Drawing.Point( 10 , 10 + 50 * i);
lblTest [i] .TabIndex = i;
lblTest [i] .Text = lblTest + i.ToString();
this .Controls.Add(lblTest [i]);
}
}
谢谢&问候
Anand。 ģ
Hi all,
I am working on windows application, so i wanted to know to create an array of non standard controls. Like i have added a custom controls(user control) in my application whose multiples are required. No of controls required is dynamic. Like for others standard controls we have something like this:
Label[] label;
How to implement for custom controls? If i do it in a similar way i get an error saying: "The control is missing(are you using a directive or assembly reference)"
Thanks in advance.
MyControl[] myControls = new MyControl[100];
But you may have to add ausing
statement to the top of your file if the control is in different namespace.
using NamespaceHoldingMyControl;
If it is in a different assembly, such as a DLL file, then you will have to add a Reference to it in your project, and theusing
line.
Try the following code
private void Form1_Activated(object sender, EventArgs e) { Label[] lblTest=new Label[5]; for(int i=0;i<5;i++) { lblTest[i] = new Label(); lblTest[i].Name = "lblTest" + i.ToString(); lblTest[i].Location = new System.Drawing.Point(10, 10 + 50 * i); lblTest[i].TabIndex = i; lblTest[i].Text = "lblTest"+i.ToString(); this.Controls.Add(lblTest[i]); } }
Thanks & Regards
Anand. G
这篇关于创建一组非标准控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!