有一个这样的类
Class Dog
{
private Lable lbName;
public Lable LbName
{
Set{lbName=value;}
Get{return lbName;}
} private Lable lbType;
public Lable LbType
{
Set{lbType=value;}
Get{return lbType;}
}
}以下是调用List<Dog> doglist = new List<Dog>();doglist.Add(new Dog());doglist[0].LbName.Text="旺财";doglist[0].LbType.Text="金巴";this.Controls.Add(doglist[0].LbName);this.Controls.Add(doglist[0].LbType);调用后把Dog这个对像的两个Lable添加到窗体后,想更改Text值,如下
doglist[0].LbName.Text="小黄";doglist[0].LbType.Text="金毛";
更改后窗体上的Text不改变,请问有什么方法让他刷新过来吗

解决方案 »

  1.   

    试一下这样去修改
     this.Controls[doglist[0].LbName.Name].Text="小黄";
     this.Controls[doglist[0].LbType.Name].Text="金毛";
      

  2.   


    private void button1_Click(object sender, EventArgs e)
    {
        List<Dog> doglist = new List<Dog>();
        doglist.Add(new Dog());
        doglist[0].LbName.Text = "旺财";
        doglist[0].LbType.Text = "金巴";
        doglist[0].LbType.Top = doglist[0].LbName.Height;
        this.Controls.Add(doglist[0].LbName);
        this.Controls.Add(doglist[0].LbType);
        MessageBox.Show("点击后更改值");
        doglist[0].LbName.Text = "小黄";
        doglist[0].LbType.Text = "金毛";
    }
    public class Dog
    {
        private Label lbName = new Label();
        public Label LbName
        {
            set { lbName = value; }
            get { return lbName; }
        }    private Label lbType = new Label();
        public Label LbType
        {
            set { lbType = value; }
            get { return lbType; }
        }
    }创建新窗体。加个按钮。双击按钮添加事件,删掉事件的方法,粘贴以上代码在窗体类中就可以看到效果。你的代码居然没报错?
    Lable or Label?
    Set or set?
    Get or get?
    你的Label都没实例化没报错?
      

  3.   

    你的代码居然没报错?
    Lable or Label?
    Set or set?
    Get or get?
    你的Label都没实例化没报错?
    确实呀。
    奇怪了。
      

  4.   

    楼上误解,上面是我发贴里就这样打的,忘了写实例化了Class Dog
    {
        private Lable lbName=new Label();    public Lable LbName
        {
            Set{lbName=value;}
            Get{return lbName;}
        }    private Lable lbType=new Label();    public Lable LbType
        {
            Set{lbType=value;}
            Get{return lbType;}
        }
    }是这个样子的,但是就算实例化了,值还是没有改变
      

  5.   

    如果这样写
    List<Lable> lb = new List<Lable>();
    lb.add(new Lable());
    lb[0].Text="aa";
    this.Controls.Add(lb[0]);
    //赋值lb[0].Text="bb";不知道我写错没,大概意思如上,如果像这样写,就没有问题。但是像上面那样写赋值后不刷新过来
      

  6.   

    不存在。你看看你的lb[0]的location和size分别是多少。