动态添加控件

来源:互联网 发布:linux 解压缩gz 编辑:程序博客网 时间:2024/06/05 20:53
for (int i = 0; i < FlowPanel_Station.Controls.Count; i++)
            {
                Panel pan = new Panel();
                pan = (Panel)FlowPanel_Station.Controls[i];
                string[] str = new string[8];
                str[0] = "站点名称:";
                str[1] = "连接状态:";
                str[2] = "监听端口:";
                str[3] = "更新时间:";
                str[4] = "";
                str[5] = "";
                str[6] = "";
                str[7] = "";


                Label[] label = new Label[8];
                Point[] point = new Point[8];


                for (int k = 0; k < 8; k++)
                {
                    if (k < 4)
                    {
                        label[k] = new Label();
                        label[k].Text = str[k];
                        label[k].Width = 70;
                        pan.Controls.Add(label[k]);
                        int x = pan.Location.X + 5;
                        int y = pan.Location.Y + label[k].Height * k + 10;
                        point[k] = new Point(x, y);
                        label[k].Location = point[k];
                    }
                    else
                    {
                        label[k] = new Label();
                        label[k].Text = str[k];
                        label[k].Width = 70;
                        pan.Controls.Add(label[k]);
                        int x = pan.Location.X + label[k - 4].Width + 5;
                        int y = pan.Location.Y + label[k - 4].Height * (k - 4) + 10;
                        point[k] = new Point(x, y);
                        label[k].Location = point[k];
                    }
                }

            }





 int a = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, "select count(*) from Objects", null));


           DataTable dt = new DataTable();
           dt = SqlHelper.GetDataSet(CommandType.Text, "select ObName,ObWorker from Objects", null).Tables[0];
           IList<Objects> ob = ModelConvertHelper<Objects>.ConvertToModel(dt);
           DataRow dr=dt.NewRow();
           工作流程管理.项目分类[] cos = new 工作流程管理.项目分类[a];
            
           
            
           for(int i=0;i<=a;i++)
           {
               cos[i] = new 工作流程管理.项目分类();
               string va=dt.Rows[i]["ObName"].ToString();
               cos[i].la.Text = va;
             
                   
               flowLayoutPanel1.Controls.Add(cos[i]);


               
           }

0 0
原创粉丝点击