public void setCanvas(UserControlCanvas canvas)
        {
            _canvas = canvas;
            _canvas.objectSelected += new UserControlCanvas.ObjectSelected(_canvas_objectSelected);
            _canvas.optionChanged += new UserControlCanvas.OptionChanged(_canvas_optionChanged);

            toolStripButton4.Checked = UserControlCanvas.isAlignGridding;
        }
        //变量替换,测试成功,如下的准备注释掉,因为不需要了。
        /**
        public static XmlDocument populateVariable(XmlDocument xmlDoc, ArrayList arrlistRow)
        {

            //有时候会遇到没arrlistRow为空的情况,那样子就不用变量替换了.
            if (arrlistRow == null)
                return xmlDoc;

            //用xpath搜索的方法来替换。
            XmlDocument myxml = xmlDoc;//赋值保存而已

            foreach (clsKeyValue keyvalue in arrlistRow)
            {
                XmlNodeList nodeList1 = myxml.SelectNodes("//VariableText[@variableName='" + keyvalue.Key + "']");

                foreach (XmlNode myXmlNode in nodeList1)
                {
                    myXmlNode.InnerText = keyvalue.Value;
                }
                XmlNodeList nodeList2 = myxml.SelectNodes("//Barcode[@variableName='" + keyvalue.Key + "']");

                foreach (XmlNode myXmlNode in nodeList2)
                {
                    myXmlNode.InnerText = keyvalue.Value;
                }
            }

            return myxml;

        }

         * */
        private int PrintBarcode(string ShapeFileName, ArrayList arrlist, int intPage)
        {
            //首先清零
            intPrintPage = 0;
            try
            {
                barcodeCanvas = new VestShapes.UserControlCanvas();
                barcodeCanvas.Loader(ShapeFileName);//先加载模板

            }
            catch (Exception ex)
            {
                ClsErrorFile.WriteLine("不能加载模板,所以不能打印", ex);

                MessageBox.Show("不能加载模板,所以不能打印,原因是"+ ex.Message);

                return 0;
                //throw;
            }

            barcodeCanvas.setArrKeyValue(arrlist);//这个是导入变量用。

            int intNumOfLine = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfLine;
            int intNumOfColumn = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.NumberOfColumn;

            myPrintDocument.DefaultPageSettings.Landscape = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.LandScape;//设置是否横向

            //设置多少张纸
            intPrintPage = (int)(intPage / (intNumOfLine*intNumOfColumn));
            if ((intPage %( intNumOfLine*intNumOfColumn)) != 0)//如果不能整除就多一张纸
                intPrintPage++;
            if (intPrintPage == 0)//有时候会出现不足一张的情况
                intPrintPage = 1;

            int intQty = intPrintPage * intNumOfLine*intNumOfColumn;
            //如上是计算了要打印多少页,因为有些条形码纸一行有多个,需要在这里打印。

            //根据纸张的连续等问题
            //设置打印机
            if (strPrinterName!="")
            {
                myPrintDocument.PrinterSettings.PrinterName = strPrinterName;
            }

            myPrintDocument.PrintController = new StandardPrintController();//这个据说可以不显示那个打印进度对框框
            myPrintDocument.DocumentName = "打印条形码";//设置完后可在打印对话框及队列中显示(默认显示document)
            //打印输出(过程)
            myPrintDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);

            myPrintDocument.OriginAtMargins = false ;//从位于可打印区域的左上角打印
            //必须得设置自定义纸张,要不然会存在顶点问题,比如说有些条形啊打印机的打印宽度为4英寸,而实际纸张宽度不是4英寸,就会存在打印时候顶点是打印机的顶点,而不是实际纸张的顶点。
            myPrintDocument.DefaultPageSettings.PaperSize = barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.BarcodePaperSize;//设置纸张
            //如下是设置边距
            /**如下的经测试会产生不可预测的偏移
            myPrintDocument.DefaultPageSettings.Margins.Top = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Top / 0.254);
            myPrintDocument.DefaultPageSettings.Margins.Bottom = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Bottom / 0.254);
            myPrintDocument.DefaultPageSettings.Margins.Left = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Left / 0.254);
            myPrintDocument.DefaultPageSettings.Margins.Right = (int)(barcodeCanvas.myShapes.BarcodePageSettings.BarcodePaperLayout.Right / 0.254);

             * */
            //每次打印
            myPrintDocument.PrinterSettings.Copies = (short)intPrintPage;//首先就是一次性全部打印完毕,设置份数就是页数.
            if (myPrintDocument.PrinterSettings.MaximumCopies < intPrintPage)//如果最高能打印的份数比要打印的页数少,就按照最高能打印的份数.
                myPrintDocument.PrinterSettings.Copies = (short)myPrintDocument.PrinterSettings.MaximumCopies;

            try
            {
                isprintDocument_PrintPage = true;

                myPrintDocument.Print();
                //这里发出打印消息。

                myPrintDocument.Dispose();//释放

            }
            catch (Exception ex)
            {
                MessageBox.Show("没有打印成功,原因:" + ex.Message);
                isprintDocument_PrintPage = false;
                return 0;
            }

            //如下是判断是否需要打印间隔
            if (isPrintJiange)
            {
                PrintDocument printDocPrintJianGe = new PrintDocument();
                printDocPrintJianGe.PrintController = new StandardPrintController();
                printDocPrintJianGe.DocumentName = "打印间隔";
                printDocPrintJianGe.PrinterSettings.Copies = 1;// 间隔只打一份。
                printDocPrintJianGe.PrintPage += new PrintPageEventHandler(printDocPrintJianGe_PrintPage);

                try
                {
                    printDocPrintJianGe.Print();
                    printDocPrintJianGe.Dispose();//释放资源

                }
                catch (Exception ex)
                {
                    MessageBox.Show("没有打印成功,原因:" + ex.Message);
                    return 0;
                }

            }

            return intQty;//返回实际打印的数量
        }
        void _canvas_optionChanged(object sender, UserControlCanvas.OptionEventArgs e)
        {
            //这个只要判断是否是select就可以了
            if (e.option == "select")
            {
                deselectAll();
                SelectBtn.Checked = true;

            }
            //throw new NotImplementedException();
        }
        void _canvas_objectSelected(object sender, UserControlCanvas.PropertyEventArgs e)
        {
            try
            {
                propertyGrid1.SelectedObjects = e.arrShapeEleSelect;
            }
            catch (System.Exception ex)
            {

            }

            //throw new NotImplementedException();
        }