如下的一个继承的控件,我自己定义了一个Parameters的属性:public class MyLinkLabel : LinkLabel
{
public MyLinkLabel()
{
this.TextAlign = ContentAlignment.MiddleCenter;
this.Anchor = AnchorStyles.None;
this.AllowDrop = true;
this.AutoSize = false;
this.Dock = DockStyle.Fill;
this.Margin = new Padding(0);
this.pamams == new ArrayList();
} private ArrayList pamams; public ArrayList Parameters
{
get
{
return this.pamams;
}
set
{
this.pamams = value;
}
}
}
可是当我在主窗口中的一个函数中申明它的一个对象,这个对象却不能访问这个Parameters属性。我试过了,如果把这个对象申请为整个Form的私有变量,在函数中是可以访问它的Parameters属性的。问题是我必须在函数中申明,因为要给Form动态地添加一些这个控件现在一共就20分了~都给了吧
{
public MyLinkLabel()
{
this.TextAlign = ContentAlignment.MiddleCenter;
this.Anchor = AnchorStyles.None;
this.AllowDrop = true;
this.AutoSize = false;
this.Dock = DockStyle.Fill;
this.Margin = new Padding(0);
this.pamams == new ArrayList();
} private ArrayList pamams; public ArrayList Parameters
{
get
{
return this.pamams;
}
set
{
this.pamams = value;
}
}
}
可是当我在主窗口中的一个函数中申明它的一个对象,这个对象却不能访问这个Parameters属性。我试过了,如果把这个对象申请为整个Form的私有变量,在函数中是可以访问它的Parameters属性的。问题是我必须在函数中申明,因为要给Form动态地添加一些这个控件现在一共就20分了~都给了吧
参考:
foreach (Control c in this.Controls)
{
if (c is MyLinkLabel ) //判断是否是
((MyLinkLabel )c). Parameters.......
}