我动态添加了一组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);
}
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);
}
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;
关系为: 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;
Location 属性要要调整 否则button叠加在一起程序关闭后在打开就不显示了 这句话我就不知道什么意思了要想重新打开还和原来一样 只有两种方法 重新for生成 和 关闭时记录所有控件信息 打开时重新加载
/// 自动生成评分项目
/// </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参考下吧
Location 属性要要调整 否则button叠加在一起