我动态添加了一组button,但是当程序关闭后在打开就不显示了,如何让动态生成的按钮每次登陆程序后还显示呢?急用。 //循环动态添加Button事件
            for (int i = 0; i < 50; i++)
            {
                Button button = new Button();
                
                button.Text = "Button ";
                button.Size = new System.Drawing.Size(118, 74);
                button.Location = new System.Drawing.Point(50, 70);                this.pictureBox1.Controls.Add(button);
                
                //调用Button_Click点击事件
                button.Click += new System.EventHandler(Button_Click);
            }

解决方案 »

  1.   

    把这个添加按钮的方法,放在窗体的load事件里面试试
      

  2.   

    CHECK_PARA1_NULL_RN(pucData, CCU_FALSE); /* 485发送消息调试定位打印 */
    CCU_SEND_TO_MONITOR_NODE(ulResourceId, pucData, uwLength);
    ucChanNum = Get485ChanNo(ulResourceId);
    if ucChanNum >= ALL_CCU_SERIAL_NUM return CCU_FALSE;
    RS485TransmitPrint(pucData, uwLength, ulResourceId, ucBit);
    ucNodeAddr = Get485NodeAddr(ulResourceId);
    if ucNodeAddr < MAX_CCU_NODE_NUM  g_aucWaitAddr[ ucChanNum ] = ucNodeAddr;
    /* 发送前先清空缓冲区 */
    tcflush(stCommParam[ucChanNum].iPort, TCIOFLUSH);         
    if CCU_OK != tcgetattr(stCommParam[ucChanNum].iPort, &options)return CCU_FALSE;
      

  3.   

    /* 修改第9位校验方式,采用整帧校验方式,需要内核配合修改,
           关系为: PARSPS置位,PARODD置位,第9比特为1
                   PARSPS清位,PARODD清位,第9比特为0 */
        switch (ucBit)
            case BIT9_HIGH_LEVEL:
                options.c_cflag |= PARSPS;
                options.c_cflag |= (PARODD | PARENB);  /* 设置为奇效验*/            
                break;
            case BIT9_LOW_LEVEL:
                ..;
                options.c_cflag |= PARENB;     /* Enable parity */
                options.c_cflag &= ~PARODD;   /* 转换为偶效验*/            
                ..;
            default:
                return CCU_FALSE;
      

  4.   

    pictureBox1 里买南方 button 放到load事件里就是了
     Location 属性要要调整  否则button叠加在一起程序关闭后在打开就不显示了 这句话我就不知道什么意思了要想重新打开还和原来一样 只有两种方法  重新for生成 和 关闭时记录所有控件信息 打开时重新加载
      

  5.   

    this.pictureBox1.Controls.Add(button);怎么放这控件里
      

  6.   

    4楼,Location调整什么,现在确实是叠加在一起了。如何调整
      

  7.   

    button 怎么可能放在pictureBox1里面???
      

  8.   

    因为我要把button放在图片上面。
      

  9.   

    for循环的时候,location改成一个动态值,例如:每次for循环位置加10!
      

  10.   

       /// <summary>
            /// 自动生成评分项目
            /// </summary>
            private void CreatProject(int type)
            {
                DataSet ds = operation.GetXiangmuByType(type);
                int width = 0;
                int pwidth = panel2.Width;
                int hang = 1;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    RadioButton rbt = new RadioButton();
                    if (width + 200 > pwidth)
                    {
                        width = 0;
                        hang += 2;
                    }
                    rbt.Location = new Point(width + 10, 10 * hang);
                    rbt.Text = ds.Tables[0].Rows[i]["prjName"].ToString() + " 总分值:" + ds.Tables[0].Rows[i]["biaozhunfen"].ToString();
                    rbt.Size = new Size(rbt.Text.Length * 16, 20);
                    rbt.Tag = ds.Tables[0].Rows[i]["xiangmucode"].ToString();
                    rbt.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                    rbt.CheckedChanged += new EventHandler(rbt_CheckedChanged); ;//+= new EventHandler(rbt_Click);
                    if (i == 0)
                    {
                        rbt.Checked = true;
                    }
                    if (type == 0)
                        this.groupBox1.Controls.Add(rbt);
                    else
                        this.groupBox2.Controls.Add(rbt);
                    width = rbt.Location.X + rbt.Size.Width + 10;            }
            }这是动态添加RadioButton 的,,Lz参考下吧
      

  11.   

    放到load事件里就是了
     Location 属性要要调整 否则button叠加在一起