コード例 #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="content">内容</param>
 /// <param name="width">长</param>
 /// <param name="height">高</param>
 /// <param name="codetype">条码类型  1:二维码  2:条形码</param>
 public BarCodeLayer(string content, int width, int height, int codetype, bool show)
     : base(LayerType.BarCode)
 {
     this.Width      = width;
     this.Height     = height;
     this.VarContent = content;
     this.CodeType   = codetype;
     this.Content    = PagerSetting.Translate(content);
     this.IsShowText = show;
 }
コード例 #2
0
        private void Tbox_Leave(object sender, EventArgs e)
        {
            base.OnLeave(e);

            Tbox.SendToBack();
            this.Content    = PagerSetting.Translate(Tbox.Text);
            this.VarContent = Tbox.Text;  //这里要还原
            TLabel.Text     = this.Content;
            Tbox.Width      = TLabel.Width;
            this.Width      = TLabel.Width + 20;
        }
コード例 #3
0
        private void init(string content, bool isSetFont, Font font, Color color)
        {
            this.VarContent = content;                         //重点属性:内容
            this.BackColor  = Color.White;
            this.Content    = PagerSetting.Translate(content); //转换后的内容
            if (isSetFont)
            {
                this.Font      = font;  //重点属性:字体
                this.ForeColor = color; //重点属性:颜色    //另外  重点属性:坐标   实时计算
            }

            TLabel          = new Label();
            TLabel.AutoSize = true;
            TLabel.Location = new Point(0, 0);
            TLabel.Text     = this.Content;
            if (isSetFont)
            {
                TLabel.Font      = font;
                TLabel.ForeColor = color;
            }
            TLabel.BackColor = Color.White;
            this.Controls.Add(TLabel);

            Tbox             = new TextBox();
            Tbox.Location    = new Point(0, 0);
            Tbox.BorderStyle = BorderStyle.None;
            Tbox.Width       = TLabel.Width;
            if (isSetFont)
            {
                Tbox.Font      = font;
                Tbox.ForeColor = color;
            }
            Tbox.Text = this.VarContent;
            this.Controls.Add(Tbox);
            this.Height = TLabel.Height;
            this.Width  = TLabel.Width + 20;
            TLabel.BringToFront();

            TLabel.Click += TLabel_Click;
            Tbox.Leave   += Tbox_Leave;
            Tbox.KeyDown += Tbox_KeyDown;
        }
コード例 #4
0
        public static Image Draw(PrintConfig cfg)
        {
            if (cfg == null || cfg.Layers == null || cfg.Layers.Count == 0)
            {
                return(null);
            }
            //根据配置还原图
            Image    img = new Bitmap(cfg.PageWidth, cfg.PageHeight);
            Graphics g   = Graphics.FromImage(img);

            for (int i = cfg.Layers.Count - 1; i >= 0; i--)
            {
                string layertype = cfg.Layers[i].GetType().ToString();
                switch (layertype.Substring(layertype.LastIndexOf(".") + 1))
                {
                case "BarCodeLayerConfig":
                    BarCodeLayerConfig bc = (BarCodeLayerConfig)cfg.Layers[i];
                    BarcodeFormat      myBarcodeFormat;
                    EncodingOptions    myEncoding;
                    if (bc.CodeType == 1)    //二维码
                    {
                        myBarcodeFormat = BarcodeFormat.QR_CODE;
                        myEncoding      = new QrCodeEncodingOptions()
                        {
                            Height       = bc.Height,
                            Width        = bc.Width,
                            Margin       = 0,
                            CharacterSet = "UTF-8",
                            PureBarcode  = !bc.IsShowText
                        };
                    }
                    else    //条形码
                    {
                        myBarcodeFormat = BarcodeFormat.CODE_128;
                        myEncoding      = new EncodingOptions()
                        {
                            Height      = bc.Height,
                            Width       = bc.Width,
                            Margin      = 0,
                            PureBarcode = !bc.IsShowText
                        };
                    }
                    BarcodeWriter writer = new BarcodeWriter
                    {
                        Format   = myBarcodeFormat,
                        Options  = myEncoding,
                        Renderer = (IBarcodeRenderer <Bitmap>)Activator.CreateInstance(typeof(BitmapRenderer))
                    };
                    Bitmap barImg = writer.Write(PagerSetting.Translate(bc.Content));
                    g.DrawImage(barImg, bc.X, bc.Y, bc.Width, bc.Height);
                    break;

                case "ImageLayerConfig":
                    ImageLayerConfig imglc = (ImageLayerConfig)cfg.Layers[i];
                    g.DrawImage(Image.FromFile(imglc.ImageFilePath), imglc.X, imglc.Y, imglc.Width, imglc.Height);
                    break;

                case "TextLayerConfig":
                    TextLayerConfig tlc = (TextLayerConfig)cfg.Layers[i];
                    //g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;//文本失真

                    g.DrawString(PagerSetting.Translate(tlc.Content), tlc.ContentFont, new SolidBrush(tlc.ContentColor), new PointF(tlc.X, tlc.Y));
                    break;

                case "LineLayerConfig":
                    LineLayerConfig lc = (LineLayerConfig)cfg.Layers[i];
                    using (Pen p = new Pen(Color.Black, lc.lineWidth))
                    {
                        if (lc.lineDirect == 1)    //横
                        {
                            g.DrawLine(p, lc.X, lc.Y, lc.X + lc.lineLength, lc.Y);
                        }
                        else    //竖
                        {
                            g.DrawLine(p, lc.X, lc.Y, lc.X, lc.Y + lc.lineLength);
                        }
                    }
                    break;

                default: break;
                }
            }
            return(img);
        }