Label sy ;
            sy = new Label();
            sy.Text = Proname;
            Controls.Add(sy);我想把sy 写成动态的怎么写?

解决方案 »

  1.   

    Label sy = new Label(); 
    sy.Text = Proname; 
    sy.Location=new Point(横坐标,纵坐标);
    Controls.Add(sy); 
      

  2.   

            for (int i=0; i<ds.Tables[0].Rows.Count;  i++)
            {  
                Label i;
                i= new Label();
                i.Text = Proname;
                Controls.Add(i);  
            }//这样写有错误,正确应该怎么写楼上的你没看明白问题, 是要类似这样,生成Label的数量。
      

  3.   

    sy动态..Label ?? =new Label();
      

  4.   

            for (int i=0; i <ds.Tables[0].Rows.Count;  i++) 
            {  
                Label sy = i; 
                sy = new Label(); 
                sy.Text = Proname; 
                Controls.Add(sy);  
            }//这样写有错误,怎么能解决下 ??
      

  5.   

       for (int i=0; i <ds.Tables[0].Rows.Count;  i++) 
            {  
                Label _Label; 
                _Label= new Label(); 
                _Label.Text = Proname; 
                Controls.Add(_Label);  
            }//这样写有错误,正确应该怎么写 i都定义过了...你还定义i
      

  6.   

            for (int i=0; i <ds.Tables[0].Rows.Count;  i++) 
            {  
                Label sy = i; 
                sy = new Label(); 
                sy.Text = Proname; 
                Controls.Add(sy);  
            }//这样写有错误,怎么能解决下 ??
    我要的是动态生成多个Label
      

  7.   

    Controls.Add(sy); 
    这个前面先定义一个tr td
    然后td.Control.Add(sy)
      

  8.   


    i是int型,怎么能赋给Label呢?
      

  9.   

    for (int i=0; i <10;  i++) 
    {  
        Label sy= new Label(); 
        sy.Text = "Lable"+(i+1).ToString(); 
        sy.Location=new System.Dreawing(10,10+i*30);//以免覆盖看不清楚 
        this.Controls.Add(sy);  
    }
      

  10.   

                for (int i = 0; i < 5; i++)
                {
                    Label sy = new Label();
                    sy.Text = "Label" + i.ToString();
                    sy.Name = "Label" + i.ToString();
                    sy.Location = new Point(100 * i, 200);
                    this.Controls.Add(sy);
                    //sy.BringToFront();
                }
    新追加的TextBox的默认Width是100,可能是你把后追加的TextBox覆盖了.可以通过sy.BringToFront();把后追加的TextBox设置在最前面.