winform中usercontrol(用户控件)     usercontrol1 ,usercontrol2 怎么能相互访问  而且通过usercontrol2 访问usercontrol1 并修改usercontrol2 中lable1的text;????

解决方案 »

  1.   

    在usercontrol中个提供一个属性,比如
    public string LabelText
    {
        get{return label1.Text;}
        set {label1.Text=value;}
    }这样在应用的页面里面就可以访问usercontrol1.LabelText="aaaaa";来设置了。
      

  2.   

    给usercontrol1控件定义一个属性,确定usercontrol1控件放在哪个容器,
    private string test;
    public string Test
    {
        get{return lable1.Text;}
        set {test = label1.Text;}
    }在userControl2中:usercontrol1所在的容器,如果直接放在Form上:
    for(int i=0; i<this.Controls.Count; i++)
    {
        if(this.Controls[i] is usercontrol1)
        {
            usercontrol1 uc = (uc)this.Controls[i];
            us.Text = "Hello, Just a Test!";
        }
    }
    会得到你想要的效果。