动态增删改控件

private void AddGroup()
        {
            for (int i = 0; i < 5; i++)
            {
                GroupBox gbox = new GroupBox();
                gbox.Name = "gbox" + i;
                gbox.Text = i + "号清洗机";
                gbox.Size = new Size(1280, 200);
                gbox.Location = new Point(30, 230 * i + 30);
                this.Controls.Add(gbox);
                AddStepLab(gbox);
            }
        }

        private void AddStepLab(GroupBox gbox)
        {
            int jiange = (1280 - 100 * 5) / 6;
            for (int i = 0; i < 5; i++)
            {
                Label lab = new Label();
                lab.Name = "labStep" + i;
                lab.Text = i + "次洗";
                lab.TextAlign = ContentAlignment.MiddleCenter;//文字居中
                lab.Location = new Point((jiange + 100) * i + jiange, 80);
                lab.Size = new Size(100, 40);
                lab.BorderStyle = BorderStyle.FixedSingle;
                gbox.Controls.Add(lab);
            }
        }

        private void AddLabInfo(int gboxNum, int labStepNum)
        {
            Control gbox = this.Controls.Find("gbox" + gboxNum, false)[0];
            Control labS = gbox.Controls.Find("labStep" + labStepNum, false)[0];
            for (int i = 0; i < 2; i++)
            {
                Label lab = new Label();
                lab.Name = "NJ100" + i;
                lab.Text = "EMM100/NJ100";
                if (i == 0)
                    lab.Location = new Point(labS.Location.X, labS.Location.Y - 20);
                else
                    lab.Location = new Point(labS.Location.X, labS.Location.Y + labS.Size.Height + 20);

                lab.Size = new Size(100, 30);
                gbox.Controls.Add(lab);
            }
        }
        private void DelLabInfo(string gboxNum, string EndCode)
        {
            Control gbox = this.Controls.Find("gbox" + gboxNum, false)[0];
            for (int i = 0; i < 2; i++)
            {
                Control labS = gbox.Controls.Find(EndCode + i, false)[0];
                gbox.Controls.Remove(labS);
            }
        }

 

posted @ 2019-11-18 14:08  蓝瑟黄昏  阅读(146)  评论(0编辑  收藏  举报