Example #1
0
        // 打印高线大标牌
        private void HwBigLablePrint(System.Drawing.Printing.PrintPageEventArgs e)
        {
            int    lableWith = 70, lableLength = 100, lineHight = 7;
            double dotMM = 4;
            // 顶部和底部的大矩形
            Size topBox = new Size(lableWith, 44);
            // 不填数据的小矩形
            Size littleBox = new Size(12, lineHight);
            // 左边空白矩形区
            Size leftBlankBox = new Size(24, lineHight);
            // 右边空白矩形区
            Size rightBlankBox = new Size(22, lineHight);

            //
            // 批号的矩形区
            Size bathNoBox = new Size(lableWith - littleBox.Width, lineHight);
            // 规格的矩形区
            Size specBox = new Size(36 - littleBox.Width, lineHight);
            // 重量矩形区
            Size weightBox = new Size();

            weightBox = specBox;
            //生产时间矩形区
            Size prodDateLeftBox  = new Size(23, lineHight);
            Size prodDateBlankBox = new Size(40, lineHight);
            // 条码矩形区
            Size barcodeBox = new Size(67, 22);

            // 地址矩形区
            Size addrBox = new Size(lableWith, 5);

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

            // 标签头部
            _rects[i] = new Rectangle(0, 0, topBox.Width, topBox.Height);
            //----------------------------------------------------------------------------- 第1行
            // 批号
            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);
            //----------------------------------------------------------------------------- 第2行
            // 标准
            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, leftBlankBox.Width, leftBlankBox.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, rightBlankBox.Width, rightBlankBox.Height);
            //----------------------------------------------------------------------------- 第3行
            // 规格
            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, leftBlankBox.Width, leftBlankBox.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, rightBlankBox.Width, rightBlankBox.Height);
            //----------------------------------------------------------------------------- 第4行
            // 生产日期
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, prodDateLeftBox.Width, prodDateLeftBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, prodDateBlankBox.Width, prodDateBlankBox.Height);
            //----------------------------------------------------------------------------- 第5行
            // 底部的条码区
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, barcodeBox.Width, barcodeBox.Height);
            // 地址区
            i++;
            _rects[i] = new Rectangle(0, _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) - 65;
                _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;
            // add by [bhb]
            StringFormat formatLeft = new StringFormat();

            formatLeft.Alignment     = StringAlignment.Near;
            formatLeft.LineAlignment = StringAlignment.Near;
            //===========================画矩形===========================
            //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);
            // 打印牌号\ 增加X的偏移量
            _rects[6].X -= 10;
            e.Graphics.DrawString(_lable.SteelType, EFont, Brushes.Black, _rects[6], formatLeft);
            //打印规格
            e.Graphics.DrawString("Φ" + _lable.Spec + "mm", EFont, Brushes.Black, _rects[8], drawFormat1);
            //打印重量
            e.Graphics.DrawString(_lable.Weight + " kg", EFont, Brushes.Black, _rects[10], drawFormat1);                                                                                                  //重量
            //打印生产日期
            e.Graphics.DrawString(_lable.Date.ToString("yyyy") + "年" + _lable.Date.ToString("MM") + "月" + _lable.Date.ToString("dd") + "日" + _lable.Term, CFont, Brushes.Black, _rects[12], drawFormat1); //生产日期
            // 打印条码
            Code128 c128 = new Code128();

            c128.printBigCode1(_lable.BarCode, _rects[13], e);

            // 打印地址
            if (Data.PrintAddress)
            {
                e.Graphics.DrawString("云南 ● 玉溪", sCFont, Brushes.Black, _rects[14], drawFormat1); //地点
            }
        }
Example #2
0
        // 打印高线大标牌
        private void HwBigLablePrint(System.Drawing.Printing.PrintPageEventArgs e)
        {
            int lableWith = 70, lableLength = 100, lineHight = 7;
            double dotMM = 4;
            // 顶部和底部的大矩形
            Size topBox = new Size(lableWith, 44);
            // 不填数据的小矩形
            Size littleBox = new Size(12, lineHight);
            // 左边空白矩形区
            Size leftBlankBox = new Size(24, lineHight);
            // 右边空白矩形区
            Size rightBlankBox = new Size(22, lineHight);

            //
            // 批号的矩形区
            Size bathNoBox = new Size(lableWith - littleBox.Width, lineHight);
            // 规格的矩形区
            Size specBox = new Size(36 - littleBox.Width, lineHight);
            // 重量矩形区
            Size weightBox = new Size();
            weightBox = specBox;
            //生产时间矩形区
            Size prodDateLeftBox = new Size(23, lineHight);
            Size prodDateBlankBox = new Size(40, lineHight);
            // 条码矩形区
            Size barcodeBox = new Size(67,22);

            // 地址矩形区
            Size addrBox = new Size(lableWith, 5);

            // 矩形坐标定义
            Rectangle[] _rects = new Rectangle[15];
            int i = 0;
            // 标签头部
            _rects[i] = new Rectangle(0, 0, topBox.Width, topBox.Height);
            //----------------------------------------------------------------------------- 第1行
            // 批号
            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);
            //----------------------------------------------------------------------------- 第2行
            // 标准
            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, leftBlankBox.Width, leftBlankBox.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, rightBlankBox.Width, rightBlankBox.Height);
            //----------------------------------------------------------------------------- 第3行
            // 规格
            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, leftBlankBox.Width, leftBlankBox.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, rightBlankBox.Width, rightBlankBox.Height);
            //----------------------------------------------------------------------------- 第4行
            // 生产日期
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, prodDateLeftBox.Width, prodDateLeftBox.Height);
            i++;
            _rects[i] = new Rectangle(_rects[i - 1].X + _rects[i - 1].Width, _rects[i - 1].Y, prodDateBlankBox.Width, prodDateBlankBox.Height);
            //----------------------------------------------------------------------------- 第5行
            // 底部的条码区
            i++;
            _rects[i] = new Rectangle(0, _rects[i - 1].Y + _rects[i - 1].Height, barcodeBox.Width, barcodeBox.Height);
            // 地址区
            i++;
            _rects[i] = new Rectangle(0, _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) - 65;
                _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;
            // add by [bhb]
            StringFormat formatLeft = new StringFormat();
            formatLeft.Alignment = StringAlignment.Near;
            formatLeft.LineAlignment = StringAlignment.Near;
            //===========================画矩形===========================
            //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);
            // 打印牌号\ 增加X的偏移量
            _rects[6].X -= 10;
            e.Graphics.DrawString(_lable.SteelType, EFont, Brushes.Black, _rects[6], formatLeft);
            //打印规格
            e.Graphics.DrawString("Φ" + _lable.Spec + "mm", EFont, Brushes.Black, _rects[8], drawFormat1);
            //打印重量
            e.Graphics.DrawString(_lable.Weight + " kg", EFont, Brushes.Black, _rects[10], drawFormat1); //重量
            //打印生产日期
            e.Graphics.DrawString(_lable.Date.ToString("yyyy") + "年" + _lable.Date.ToString("MM") + "月" + _lable.Date.ToString("dd") + "日" + _lable.Term, CFont, Brushes.Black, _rects[12], drawFormat1); //生产日期
            // 打印条码
            Code128 c128 = new Code128();
            c128.printBigCode1(_lable.BarCode, _rects[13], e);

            // 打印地址
            if (Data.PrintAddress)
            {
                e.Graphics.DrawString("云南 ● 玉溪", sCFont, Brushes.Black, _rects[14], drawFormat1); //地点
            }
        }