私はこれuserControlを含むものを持っていますListBox。ListBox別のからアクセスしたいuserControl。
例えば:
UserControl1.ListBox1.Items.Count;
ユーザーコントロールにパブリックプロパティItemsCountを追加します
public int ItemsCount
{
get { return ListBox1.Items.Count; }
}
or
public ListBox MyListBox
{
get { return ListBox1; }
}
リストボックス全体にアクセスするには
ListBoxあなたの最初のプロパティを作成し、usercontrolそのように取得します
public ListBox lstBox
{
get { return this.listBox1;}
}
次に、そのような他のユーザーコントロールからリストボックスにアクセスします
usercontrol1 obj = new usercontrol1();
int itemCount = obj.lstBox.Items.Count ;