从另一个 userControl c# 访问 userControl 上的对象 [英] Accessing an object on userControl from another userControl c#

查看:48
本文介绍了从另一个 userControl c# 访问 userControl 上的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have this userControl which contains ListBox. I want to access that ListBox from another userControl.

例如:

UserControl1.ListBox1.Items.Count;

推荐答案

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

Add A Public Property ItemsCount in your user control

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

or

public ListBox MyListBox 
{
    get { return ListBox1; }
}

访问整个列表框

这篇关于从另一个 userControl c# 访问 userControl 上的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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