您的位置:首页 > 其它

动态添加控件

2016-06-16 20:20 337 查看
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]);

               

           }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: