//test buttom
        private void button3_Click(object sender, EventArgs e)
        {
            int pageNum = 3;

            corel.ShapeRange sr_template = (corel.ShapeRange)templates[0];
            corel.Shape      sh_template = sr_template.Shapes.FindShape("plate");
            double           dx          = sh_template.SizeWidth;
            double           dy          = sh_template.SizeHeight;

            corelApp.ActiveDocument.AddPages(pageNum);

            IEnumerator enumerator = corelApp.ActiveDocument.Pages.GetEnumerator();

            corel.Page current_page;
            list_index = 1;
            while (enumerator.MoveNext())
            {
                current_page = (corel.Page)enumerator.Current;
                current_page.Activate();
                current_page.SetSize(dx * 4, dy * 4);


                System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
                stopwatch.Start(); // 开始监视代码运行时间
                myOptimize(true, true);
                MakeAPage(dx, dy);
                myOptimize(true, false);
                stopwatch.Stop(); // 停止监视
                rTB_info.AppendText("每页运行时间:" + stopwatch.Elapsed.TotalMilliseconds.ToString() + "\n");
            }
            list_index = 1;
        }
        //add template
        private void button5_Click(object sender, EventArgs e)
        {
            corel.Shapes     shapes     = corelApp.ActiveSelection.Shapes; //get selected shapes
            corel.ShapeRange shapeRange = shapes.All();                    // used for clone

            templates.Add(shapeRange);
            lb_tcount.Text = templates.Count.ToString();
        }
        //make a qrcode
        private void myQrcode(string name, corel.Shape sh_qrcode, string imgpath)
        {
            corelApp.ActiveLayer.Import(imgpath);
            corel.Shape      bm_qrcode = corelApp.ActiveShape;
            corel.ShapeRange sr_qrcode = bm_qrcode.Bitmap.Trace(corel.cdrTraceType.cdrTraceLineArt, 25, 100, DeleteOriginalObject: true, ColorCount: 2, ColorMode: corel.cdrColorType.cdrColorBlackAndWhite, RemoveBackground: false).Finish();

            //sr_qrcode.Group();
            sr_qrcode.SetSize(sh_qrcode.SizeWidth, sh_qrcode.SizeHeight);
            sr_qrcode.SetPosition(sh_qrcode.PositionX, sh_qrcode.PositionY);
        }
        private void MakeAPage(double dx, double dy)
        {
            int cols = int.Parse(tb_cols.Text);
            int rows = int.Parse(tb_rows.Text);


            for (int x = 0; x < 4; x++)
            {
                for (int y = 1; y < 5; y++)
                {
                    if (list_index > datas.Count - 1)
                    {
                        corelApp.Optimization = false;
                        corelApp.ActiveWindow.Refresh();
                        return;
                    }
                    string[] data = (string[])datas[list_index];
                    string   key  = data[2];
                    if (!data[1].Contains("号"))
                    {
                        corel.ShapeRange shapeRange = (corel.ShapeRange)templates[data[1].Length - 1];
                        MakeNewPlate(shapeRange, data, x * dx, y * dy);
                    }
                    else
                    {
                        corel.ShapeRange shapeRange = (corel.ShapeRange)templates[4];
                        if (data[1].Contains("之"))
                        {
                            shapeRange = (corel.ShapeRange)templates[5];
                        }
                        else
                        {
                            shapeRange = (corel.ShapeRange)templates[data[1].Length - 2];
                        }
                        MakeNewPlate(shapeRange, data, x * dx, y * dy);
                    }
                    list_index++;
                }
            }

            //corelApp.Optimization = false;
            //corelApp.ActiveWindow.Refresh();
        }
        private void MakeNewPlate(ShapeRange sr_origin, string[] data, double x, double y)
        {
            string key = data[2];

            //clone to the grid
            corel.Shape      sh_plate    = sr_origin.Shapes.FindShape("plate");
            corel.Shape      sh_pn_orign = sr_origin.Shapes.FindShape("H_第1列");
            corel.ShapeRange sr_new      = sr_origin.Clone();
            sr_new.SetPosition(x, y);

            //replace things
            corel.Shape sh_pn      = sr_new.Shapes.FindShape("H_第1列");
            corel.Text  platenum_1 = sr_new.Shapes.FindShape("H_第2列").Text;
            corel.Shape sh_qrLB    = sr_new.Shapes.FindShape("qrLB");
            corel.Shape sh_qrRT    = sr_new.Shapes.FindShape("qrRT");

            sh_pn.Text.Story.Text = data[0];
            sh_pn.SetSize(sh_pn_orign.SizeWidth, sh_pn_orign.SizeHeight);//resize the font

            if (dict_qrPath.ContainsKey(key))
            {
                myQrcode("a", sh_qrLB, dict_qrPath[key][0]);
                myQrcode("a", sh_qrRT, dict_qrPath[key][1]);
            }

            if (!data[1].Contains("号"))
            {
                platenum_1.Story.Text = data[1];
            }
            else
            {
                string[]    num        = data[1].Split('号');
                corel.Shape platenum_2 = sr_new.Shapes.FindShape("H_第3列");
                platenum_1.Story.Text = num[0];
                //platenum_1.SetSize(sh_num1_orign.SizeWidth, sh_num1_orign.SizeHeight);//resize the font
                platenum_2.Text.Story.Text = "号" + num[1];
                //platenum_2.SetSize(sh_num2_orign.SizeWidth, sh_num2_orign.SizeHeight);//resize the font
            }
        }
        //generate a lot of plates
        private void button1_Click(object sender, EventArgs e)
        {
            myOptimize(true, true);
            corel.Shapes     shapes     = corelApp.ActiveSelection.Shapes; //get selected shapes
            corel.Shape      plate      = shapes.FindShape("plate");
            corel.ShapeRange shapeRange = shapes.All();                    // used for clone
            MessageBox.Show(shapeRange.Count.ToString());
            double dx = plate.RightX - plate.LeftX;
            double dy = plate.TopY - plate.BottomY;

            int count = 1;

            for (int x = 1; x < 3; x++)
            {
                for (int y = 1; y < 3; y++)
                {
                    string[]         data         = (string[])datas[count];
                    corel.ShapeRange sr           = shapeRange.Clone(x * dx, y * dy);
                    corel.Shapes     shs          = sr.Shapes;
                    corel.Text       sh_platename = shs.FindShape("H_第1列").Text;
                    corel.Text       sh_platenum  = shs.FindShape("H_第2列").Text;
                    if (sh_platename.IsArtisticText)
                    {
                        //sh_platename.Replace("大氹村前街十二巷", "我卢本伟没有开挂", false, ReplaceAll: true);
                        sh_platename.Story.Text = data[0];
                    }
                    if (sh_platenum.IsArtisticText)
                    {
                        //String num = count.ToString();
                        //sh_platenum.Replace("1", num, false, ReplaceAll: true);
                        sh_platenum.Story.Text = data[1];
                    }
                    count++;
                }
            }
            myOptimize(true, false);
        }