Ejemplo n.º 1
0
        public string ModelShapes = "圆角矩形"; //模板的形状

        #endregion Fields

        #region Methods

        /// <summary>
        /// 绘制一个背景
        /// </summary>
        /// <param name="g"></param>
        /// <param name="fx">这个背景偏移相当于这个模板的X坐标</param>
        /// <param name="fy">这个背景偏移相当于这个模板的Y坐标</param>
        /// <param name="Zoom"></param>
        /// <param name="listMatrix"></param>
        public void DrawModelBackground(Graphics g, float fx, float fy, float Zoom, List<Matrix> listMatrix)
        {
            //比如说背景是一张A4大小的纸张,那么其X,Y坐标就是画布的偏移。。。

            //单位一定要是MM。
            g.PageUnit = GraphicsUnit.Millimeter;

            //如下被认为可以清晰文字。
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.CompositingQuality = CompositingQuality.HighQuality;

            float fltPenWidth = 0.5f / Zoom;//绘制纸张边距的画笔宽度

            //基本上只是一个调用ShapeEle来绘图的方法

            switch (ModelShapes)
            {
                case "方形":
                    ShapeRect shapeRect = new ShapeRect();
                    shapeRect.X = fx ;
                    shapeRect.Y = fy ;
                    shapeRect.Width = BarcodePaperLayout.ModelWidth ;
                    shapeRect.Height = BarcodePaperLayout.ModelHeight ;
                    shapeRect.Zoom = Zoom;
                    shapeRect.FillColor = Color.White;
                    shapeRect.isFill = true;
                    shapeRect.PenWidth = fltPenWidth;
                    shapeRect.Draw(g,listMatrix);
                    break;
                case "圆角矩形":
                     ShapeRoundRect  shapeRouneRect = new ShapeRoundRect();
                     shapeRouneRect.X = fx ;
                     shapeRouneRect.Y = fy ;
                     shapeRouneRect.Width = BarcodePaperLayout.ModelWidth ;
                     shapeRouneRect.Height = BarcodePaperLayout.ModelHeight ;
                     shapeRouneRect.Zoom = Zoom;
                     shapeRouneRect.CornerRadius = BarcodePaperLayout.CornerRadius;
                     shapeRouneRect.FillColor = Color.White;
                     shapeRouneRect.isFill = true;
                     shapeRouneRect.PenWidth = fltPenWidth;
                     shapeRouneRect.Draw(g,listMatrix);
                    break;
                case "椭圆形":
                    ShapeEllipse shapeEllipse = new ShapeEllipse();
                    shapeEllipse.X = fx ;
                    shapeEllipse.Y = fy ;
                    shapeEllipse.Width = BarcodePaperLayout.ModelWidth ;
                    shapeEllipse.Height = BarcodePaperLayout.ModelHeight ;
                    shapeEllipse.Zoom = Zoom;
                    shapeEllipse.FillColor = Color.White;
                    shapeEllipse.isFill = true;
                    shapeEllipse.PenWidth = fltPenWidth;
                    shapeEllipse.Draw(g,listMatrix);
                    break;
                case "CD":
                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 如下的这个只是在一个picture上绘制条形码纸张的布局的,只是预览窗口需要这个,其他的都不需要的。
        /// </summary>
        /// <param name="pic"></param>
        public void DrawModelsBackgroundOnPaper(Graphics g , float fW , float fH)
        {
            //纸张左上角的边距,只是这个不能太靠边而已,没有其他的作用
            float fltBianJuX =0/ 25.4f * g.DpiX;
            float fltBianJuY = 0 / 25.4f * g.DpiY;

            float fwzoom = (fW- 2*fltBianJuX) / (BarcodePaperLayout.PaperWidth / 25.4f * g.DpiX);
            float fhzoom = (fH- 2*fltBianJuY) / (BarcodePaperLayout.PaperHeight / 25.4f * g.DpiY);

            float fzoom = fwzoom > fhzoom ? fhzoom : fwzoom;

            float fltPenWidth = 0.5f / fzoom;//绘制纸张边距的画笔宽度

            try
            {
                g.Clear(Color.Beige);//清空

                //如下被认为可以清晰文字。
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.CompositingQuality = CompositingQuality.HighQuality;

                g.PageUnit = GraphicsUnit.Millimeter;//毫米单位

                //绘制纸张的背景
                ShapeRect shapeRect = new ShapeRect();
                shapeRect.X = fltBianJuX;
                shapeRect.Y = fltBianJuY;
                shapeRect.Width = BarcodePaperLayout.PaperWidth;
                shapeRect.Height = BarcodePaperLayout.PaperHeight;
                shapeRect.Zoom = fzoom;
                shapeRect.PenWidth = fltPenWidth;
                shapeRect.Draw(g,null);

                //如下是绘制各个模板的背景
                for (int i = 0; i < BarcodePaperLayout.NumberOfColumn; i++)
                {
                    for (int j =0; j < BarcodePaperLayout.NumberOfLine; j++)
                    {
                        //计算每个模板的左上角的坐标
                        float fx = BarcodePaperLayout.Left+fltBianJuX +(i)*BarcodePaperLayout.HorizontalInterval+ i * BarcodePaperLayout.ModelWidth;
                        float fy = BarcodePaperLayout.Top+fltBianJuY +(j)*BarcodePaperLayout.VerticalInterval+ j * BarcodePaperLayout.ModelHeight;
                        DrawModelBackground(g, fx, fy, fzoom);
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("预览不成功,原因是: "+ex.Message);
                //ClsErrorFile.WriteLine("预览不成功,原因是: ",ex);
                //throw;
            }
        }