Example #1
0
        // 打印高线小标牌
        private void SmallCardPrint(System.Drawing.Printing.PrintPageEventArgs e)
        {
            int    lableWith = 65, lableLength = 55, lineHight = 8;
            double dotMM = 4;
            // 顶部和底部的大矩形
            Size bigBox = new Size(lableWith, 14);
            // 不填数据的小矩形
            Size littleBox = new Size(11, lineHight);
            // 批号的矩形区
            Size bathNoBox = new Size(lableWith - littleBox.Width, lineHight);
            // 规格的矩形区
            Size specBox = new Size(32 - littleBox.Width, lineHight);
            // 重量矩形区
            Size weightBox = new Size();

            weightBox = specBox;
            //生产时间矩形区
            Size prodBox = new Size(36, lineHight);
            // 条码矩形区
            Size barcodeBox = new Size();

            barcodeBox         = bigBox;
            barcodeBox.Height -= 5;
            // 地址矩形区
            Size addrBox = new Size(46, 5);

            // 矩形坐标定义
            Rectangle[] _rects = new Rectangle[10];
            int         i      = 0;

            // 标签头部
            _rects[i] = new Rectangle(0, 0, bigBox.Width, bigBox.Height);
            // 批号
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, bathNoBox.Width, bathNoBox.Height);
            // 规格
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, specBox.Width, specBox.Height);
            // 重量
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, weightBox.Width, weightBox.Height);
            // 生产日期
            i++;
            _rects[i] = new Rectangle(22, _rects[i - 1].Y + _rects[i - 1].Height, prodBox.Width, prodBox.Height);
            // 底部的条码区
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, barcodeBox.Width, barcodeBox.Height);
            // 地址区
            i++;
            _rects[i] = new Rectangle(10, _rects[i - 1].Y + _rects[i - 1].Height, addrBox.Width, addrBox.Height);
            // 坐标单位转换 mm -> dot
            for (i = 0; i < _rects.Length; i++)
            {
                _rects[i].X      = (int)(_rects[i].X * dotMM);
                _rects[i].Y      = (int)(_rects[i].Y * dotMM) - 40;
                _rects[i].Width  = (int)(_rects[i].Width * dotMM);
                _rects[i].Height = (int)(_rects[i].Height * dotMM);
            }

            // 定义字体
            Font CFont  = new Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font EFont  = new Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sEFont = new Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sCFont = new Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            //Font ssCFont = new Font("隶书", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

            Font cCFont = new Font("隶书", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font eEFont = new Font("Arial", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            StringFormat drawFormat1 = new StringFormat();

            drawFormat1.Alignment     = StringAlignment.Center;
            drawFormat1.LineAlignment = StringAlignment.Center;
            //===========================画矩形===========================
            //Pen rectPen = new Pen(Brushes.Blue, 2);
            //for (i = 0; i < _rects.Length; i++)
            //{
            //    e.Graphics.DrawRectangle(rectPen, _rects[i]);
            //}

            //===========================打印数据===========================
            //打印批次号
            if (_lable.BandNo.Length == 1)
            {
                e.Graphics.DrawString(_lable.BatchNo + " 0" + _lable.BandNo, EFont, Brushes.Black, _rects[2], drawFormat1);
            }
            else
            {
                e.Graphics.DrawString(_lable.BatchNo + " " + _lable.BandNo, EFont, Brushes.Black, _rects[2], drawFormat1);
            }

            //打印规格
            e.Graphics.DrawString("Φ" + _lable.Spec + "mm", EFont, Brushes.Black, _rects[4], drawFormat1);
            //打印重量
            e.Graphics.DrawString(_lable.Weight + " kg", EFont, Brushes.Black, _rects[6], drawFormat1);                                                                                                  //重量
            //打印生产日期
            e.Graphics.DrawString(_lable.Date.ToString("yyyy") + "年" + _lable.Date.ToString("MM") + "月" + _lable.Date.ToString("dd") + "日" + _lable.Term, CFont, Brushes.Black, _rects[7], drawFormat1); //生产日期
            // 打印条码
            Code128 c128 = new Code128();

            c128.printSmallCode(_lable.BarCode, _rects[8], e);
            // 打印地址
            if (_lable.PrintAddress)
            {
                e.Graphics.DrawString("云南 ● 玉溪", sCFont, Brushes.Black, _rects[9], drawFormat1);                      //地点
            }
        }
Example #2
0
        // 打印高线小标牌
        private void SmallCardPrint(System.Drawing.Printing.PrintPageEventArgs e)
        {
            int lableWith = 65, lableLength=55, lineHight = 8;
            double dotMM = 4;
            // 顶部和底部的大矩形
            Size bigBox = new Size(lableWith,14);
            // 不填数据的小矩形
            Size littleBox = new Size(11, lineHight);
            // 批号的矩形区
            Size bathNoBox = new Size(lableWith-littleBox.Width,lineHight);
            // 规格的矩形区
            Size specBox = new Size(32-littleBox.Width, lineHight);
            // 重量矩形区
            Size weightBox = new Size();
            weightBox = specBox;
            //生产时间矩形区
            Size prodBox = new Size(36, lineHight);
            // 条码矩形区
            Size barcodeBox = new Size();
            barcodeBox = bigBox;
            barcodeBox.Height -= 5;
            // 地址矩形区
            Size addrBox = new Size(46,5);

            // 矩形坐标定义
            Rectangle[] _rects = new Rectangle[10];
            int i = 0;
            // 标签头部
            _rects[i] = new Rectangle(0, 0, bigBox.Width, bigBox.Height);
            // 批号
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i-1].X+ _rects[i-1].Width, _rects[i-1].Y, bathNoBox.Width, bathNoBox.Height);
            // 规格
            i++;
            _rects[i] = new Rectangle(0, _rects[i-1].Y + _rects[i-1].Height, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, specBox.Width, specBox.Height);
            // 重量
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, littleBox.Width, littleBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, weightBox.Width, weightBox.Height);
            // 生产日期
            i++;
            _rects[i] = new Rectangle(22, _rects[i - 1].Y + _rects[i - 1].Height, prodBox.Width, prodBox.Height);
            // 底部的条码区
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, barcodeBox.Width, barcodeBox.Height);
            // 地址区
            i++;
            _rects[i] = new Rectangle(10, _rects[i - 1].Y + _rects[i - 1].Height, addrBox.Width, addrBox.Height);
            // 坐标单位转换 mm -> dot
            for (i = 0; i < _rects.Length; i++)
            {
                _rects[i].X = (int)(_rects[i].X * dotMM);
                _rects[i].Y = (int)(_rects[i].Y*dotMM) -40;
                _rects[i].Width = (int)(_rects[i].Width * dotMM);
                _rects[i].Height = (int)(_rects[i].Height * dotMM);
            }

            // 定义字体
            Font CFont = new Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font EFont = new Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sEFont = new Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sCFont = new Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            //Font ssCFont = new Font("隶书", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

            Font cCFont = new Font("隶书", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font eEFont = new Font("Arial", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            StringFormat drawFormat1 = new StringFormat();
            drawFormat1.Alignment = StringAlignment.Center;
            drawFormat1.LineAlignment = StringAlignment.Center;
            //===========================画矩形===========================
            //Pen rectPen = new Pen(Brushes.Blue, 2);
            //for (i = 0; i < _rects.Length; i++)
            //{
            //    e.Graphics.DrawRectangle(rectPen, _rects[i]);
            //}

            //===========================打印数据===========================
            //打印批次号
            if (_lable.BandNo.Length == 1)
                e.Graphics.DrawString(_lable.BatchNo + " 0" + _lable.BandNo, EFont, Brushes.Black, _rects[2], drawFormat1);
            else
                e.Graphics.DrawString(_lable.BatchNo + " " + _lable.BandNo, EFont, Brushes.Black, _rects[2], drawFormat1);

            //打印规格
            e.Graphics.DrawString("Φ" + _lable.Spec + "mm", EFont, Brushes.Black, _rects[4], drawFormat1);
            //打印重量
            e.Graphics.DrawString(_lable.Weight + " kg", EFont, Brushes.Black, _rects[6], drawFormat1); //重量
            //打印生产日期
            e.Graphics.DrawString(_lable.Date.ToString("yyyy") + "年" + _lable.Date.ToString("MM") + "月" + _lable.Date.ToString("dd") + "日" + _lable.Term, CFont, Brushes.Black, _rects[7], drawFormat1); //生产日期
            // 打印条码
            Code128 c128 = new Code128();
            c128.printSmallCode(_lable.BarCode,_rects[8], e);
            // 打印地址
            if (_lable.PrintAddress) e.Graphics.DrawString("云南 ● 玉溪", sCFont, Brushes.Black, _rects[9], drawFormat1); //地点
        }