如题所示,请大神帮我解决!.net

解决方案 »

  1.   

    用委托 ,google  “c# 线程 委托”
      

  2.   

      public delegate void AddControlHanddler();        private void Form1_Load(object sender, EventArgs e)
            {
                new System.Threading.Thread(new System.Threading.ThreadStart(AddControlThread)).Start();
            }        private void AddControlThread()
            {
                AddControlHanddler add = new AddControlHanddler(AddControlFunc);
                this.Invoke(add);
            }        //线程动态创建100个按钮
            private void AddControlFunc()
            {
                for (int i = 0; i < 100; i++)
                {
                    Button b = new Button();
                    b.Text="按钮" + (i+1).ToString();
                    b.Location = new Point(10, 10 + 30 * i);
                    b.Size = new Size(75, 24);
                    this.Controls.Add(b);
                }
            }
      

  3.   

    那你在创建循环里加上DoEvents,就不会卡了   //线程动态创建100个按钮
            private void AddControlFunc()
            {
                for (int i = 0; i < 100; i++)
                {
                    Button b = new Button();
                    b.Text="按钮" + (i+1).ToString();
                    b.Location = new Point(10, 10 + 30 * i);
                    b.Size = new Size(75, 24);
                    this.Controls.Add(b);
                    Application.DoEvents(); //加上这句
                }
            }
      

  4.   

    大神,确实可以了,我去看看MSDN的这个Application.DoEvents()是什么意思!