解决方案 »

  1.   

    你把  textBox 放到一个list集合,再进行便利。
      

  2.   

    另外,textbox[]=new textbox[]{textbox1,textbox2,textbox3};
    所有对象都可以放数组里的
      

  3.   


            public void GenerateRandom()
            {
                if (!judgeThread)
                {
                    for (int i = 0; i < this.groupBox1.Controls.Owner.Controls.Count; i++)
                    {
                        if (i == this.groupBox1.Controls.Owner.Controls.Count - 1)
                        {
                            judgeThread = true;
                        }
                        if (this.groupBox1.Controls.Owner.Controls[i] is TextBox)
                        {
                            if (this.groupBox1.Controls.Owner.Controls[i].InvokeRequired)
                            {
                                setd = GenerateRandom;
                                this.groupBox1.Controls.Owner.Controls[i].Invoke(setd);
                            }
                            else
                                continue;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < this.groupBox1.Controls.Owner.Controls.Count; i++)
                    {
                        if (this.groupBox1.Controls.Owner.Controls[i] is TextBox)
                        {
                           // this.groupBox1.Controls.Owner.Controls[i].Text = rd.Next(20).ToString();
                           //改成下面的写法
                            this.groupBox1.Controls.Owner.Controls[i].Invoke(new MethodInvoker(() => 
                            {
                                this.groupBox1.Controls.Owner.Controls[i].Text = rd.Next(20).ToString(); 
                            }));
                        }
                    }
                }
            }
      

  4.   

    你好,大鸟,你的方法确实有用,有个问题,如此写的话
     if (!judgeThread)
                {
                    for (int i = 0; i < this.groupBox1.Controls.Owner.Controls.Count; i++)
                    {
                        if (i == this.groupBox1.Controls.Owner.Controls.Count - 1)
                        {
                            judgeThread = true;
                        }
                        if (this.groupBox1.Controls.Owner.Controls[i] is TextBox)
                        {
                            if (this.groupBox1.Controls.Owner.Controls[i].InvokeRequired)
                            {
                                setd = GenerateRandom;
                                this.groupBox1.Controls.Owner.Controls[i].Invoke(setd);
                            }
                            else
                                continue;
                        }
                    }
                }
    这段代码都没用了?(这段代码的本意就是让这些控件invoke,而您给我的答案又invoke了)
    我想知道我的代码问题出在哪
      

  5.   

    一般是重开一个Threa做操作
    也可以使用易用的 如 BackgroundWorker