1

我有这个userControl包含ListBox. 我想ListBox从另一个访问它userControl

例如:

UserControl1.ListBox1.Items.Count;
4

2 回答 2

4

在您的用户控件中添加公共属性 ItemsCount

public int ItemsCount 
{
    get { return ListBox1.Items.Count; }
}

or

public ListBox MyListBox 
{
    get { return ListBox1; }
}

访问整个列表框

于 2012-07-26T09:45:24.863 回答
2

ListBox在你的第一个属性中usercontrol获得它

public ListBox lstBox
{
  get { return this.listBox1;}
}

现在像这样从其他用户控件访问 ListBox

usercontrol1 obj = new usercontrol1();
int itemCount =  obj.lstBox.Items.Count ;
于 2012-07-26T09:49:00.860 回答