循环动态生成多个Button控件,运行一段时间后,出错,并提示“创建窗口句柄时出错”。请各位大侠帮忙解决一下!

解决方案 »

  1.   

      相关部分的主要代码如下所示:                
                        int x = 12;
                        int y = 27;
                        int xx = 248;
                        int yy = 190;
                        x = i % 4 * xx + x;
                        y = i / 4 * yy + y;
                        DataGridView dg = new DataGridView();
                        dg.Location = new Point(x, y);
                        dg.Size = new Size(xx, yy);
                        dg.DataSource = sqlds.Tables[0];
                        this.Controls.Add(dg);
                        Button btn = new Button();
                        btn.Location = new Point(100, 160);
                        btn.Name = mineid;//记录矿井的编号
                          btn.Size = new Size(70, 30);
                        btn.BackColor = Color.Silver;
                        dg.Controls.Add(btn); //运行一段时间后,这儿出错“创建窗口句柄时出错”
                        btn.Text = "详细信息";
                        btn.Click += new EventHandler(button_Click);
    请各位大侠指点一下!
      

  2.   

    试了你的代码 ,还没发现错误
    先把
    DataGridView dg ;Button btn;声明称全局的看看
      

  3.   

    是主窗口设置了
    ismdicontainer=true
    主窗口内没有 对象