C#(winform)中如何循环用户控件?

解决方案 »

  1.   

    http://hi.baidu.com/dwxgundam/blog/item/8606a9a74732b2b5caefd0f1.html
    给LZ提供思路
      

  2.   

    C#(winform)中如何循环用户控件?
    例如创建了个火车车厢的用户控件,现在要循环的显示到窗体上,火车的节数是数据库查询的结果
      

  3.   

    使用foreach能举个例子吗?我这个是winform
      

  4.   

    WINFORM方法也差不多啊!拖好控件,然后调用我给网址那个方法就可以了
      

  5.   

    递归
    public ArrayList GetControls()
            {
                ArrayList controls = new ArrayList();                        GetDetailControl(ref controls, this);            return controls;
                
            }        private void GetDetailControl(ref ArrayList collection, Control control)
            {
                foreach (Control c in control.Controls)
                {
                    collection.Add(c);                if (c.Controls.Count > 0)
                        GetDetailControl(ref collection, c);
                }
            }
      

  6.   

    反正今天还在放假,帮LZ调试了下按钮的代码
            private void button1_Click(object sender, EventArgs e)
            {
                FindTextBox(this);
            }
            //创建方法
    protected void FindTextBox(Control c)
            {
                if (c.Controls != null)
                {
                    foreach (Control x in c.Controls)
                    {
                        if (x is TextBox)
                        {
                            ((TextBox)x).Text = "";
                        }
                        FindTextBox(x);
                    }
                }
            }
      

  7.   

    点击按钮就会遍历全部textbox 控件并且 全部清空
      

  8.   

    就像asp.net的datalist一样,数据库查出的值是多少,例如是a=10,那么在窗体上显示10个一样的控件
      

  9.   

    不是吧, 这问题~~~~
    int temp = 10;//这是未知的数量,从数据库获取
    TextBox tb ;
    for(int i=0;i<temp;i++)
    {
       tb = new TextBox();
       tb.Location = new Pooint(x,y);//x y 自己想办法计算位置,看你要多少个控件一排?
       this.Panel1.Controls.Add(tb);//添加到你要显示的容器中去
    }
      

  10.   

    每次remove掉所有的控件,数据库查出来之后10之后,new10个控件,添加到controls里
      

  11.   

    创建一个车厢控件,New 100个实例之后统统 Controls.Add("Ctrl")。
    难道不能成功?for(int i=0;i<100;i++)
    {
      TrainBox box = new TrainBox ();
      box.Name="box" + i.ToString();
      Train.Boxes.Add(box);
    }南车就这样造了一列火车了,楼主你再New一个火车头加到前面去吧。
      

  12.   

    再加一条语句:
    tb.Show();

    tb.Visable = true;
      

  13.   


    LZ不好意思 ,我写的代码没有测试,但思路就那样了,嘿嘿, 问题能解决就OK啦