Example #1
0
        /// <summary>
        /// 打印或者显示在指定画布,该方法的调用用在显示报表
        /// <remarks>使用x,y偏移量是为了绘图转换坐标系方便</remarks>
        /// </summary>
        /// <param name="g">绘图图面,拥有该参数是为了可以灵活的转移图形的输出画面</param>
        /// <param name="x">横坐标位置的偏移值</param>
        /// <param name="y">纵坐标位置的偏移值</param>
        public void Print(Canvas ca, float x, float y)
        {
            MoveX = x;
            MoveY = y;
            if (null == ca || null == ca.Graphics)
            {
                return;
            }
            if (string.IsNullOrEmpty(RealText) && !string.IsNullOrEmpty(Text))
            {
                RealText = Text;
            }
            else if (string.IsNullOrEmpty(RealText))
            {
                return;
            }
            QRCodeControl bc = null;

            try
            {
                bc = new QRCodeControl();
                bc.IncludeLabel    = IncludeLabel;
                bc.backColor       = BackColor;
                bc.foreColor       = ForeColor;
                bc.CorrectionLevel = CorrectionLevel;
                bc.EncodedMode     = EncodedMode;
                bc.QRCodeScale     = QRCodeScale;
                bc.RawData         = RealText;
                Image img = bc.PictureBoxImage;
                if (null != img)
                {
                    ca.Graphics.DrawImage(img, x, y, this.Width, this.Height);
                    img.Dispose();
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (!string.IsNullOrEmpty(message))
                {
                    SizeF size = ca.Graphics.MeasureString(ErrorText, this.Font);
                    float left = ((float)this.Width - size.Width) / 2;
                    if (left < 0)
                    {
                        left = x;
                    }
                    else
                    {
                        left += x;
                    }
                    float top = ((float)this.Height - size.Height) / 2;
                    if (top < 0)
                    {
                        top = y;
                    }
                    else
                    {
                        top += y;
                    }
                    float width  = this.Width > size.Width ? size.Width : this.Width;
                    float height = this.Height > size.Height ? size.Height : this.Height;
                    ca.Graphics.DrawString(ErrorText, this.Font, Brushes.Red, new RectangleF(left, top, width, height));
                }
            }
            finally
            {
                if (null != bc)
                {
                    bc.Dispose();
                }
            }
            if (null != Border)
            {
                Border.Print(ca, x, y);
            }
        }
Example #2
0
        /// <summary>
        /// 直接绘制
        /// </summary>
        /// <param name="ca"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public override void DirectDraw(Canvas ca, float x, float y, float dpiZoom)
        {
            SetBorder();
            MoveX = x;
            MoveY = y;
            if (null == ca || null == ca.Graphics)
            {
                return;
            }
            if (string.IsNullOrEmpty(RealText) && !string.IsNullOrEmpty(Text))
            {
                RealText = Text;
            }
            else if (string.IsNullOrEmpty(RealText))
            {
                return;
            }

            try
            {
                if (null == _QRCodeControl)
                {
                    _QRCodeControl = new QRCodeControl();
                    _QRCodeControl.IncludeLabel    = IncludeLabel;
                    _QRCodeControl.backColor       = BackColor;
                    _QRCodeControl.foreColor       = ForeColor;
                    _QRCodeControl.CorrectionLevel = CorrectionLevel;
                    _QRCodeControl.EncodedMode     = EncodedMode;
                    _QRCodeControl.QRCodeScale     = _QRCodeScale;
                    _QRCodeControl.Version         = Version;
                    _QRCodeControl.RawData         = RealText;
                }
                Image img = _QRCodeControl.PictureBoxImage;
                if (null != img)
                {
                    ca.Graphics.DrawImage(img, x, y, this.Width, this.Height);
                    img.Dispose();
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (!string.IsNullOrEmpty(message))
                {
                    SizeF size = ca.Graphics.MeasureString(ErrorText, this.Font);
                    float left = ((float)this.Width - size.Width) / 2;
                    if (left < 0)
                    {
                        left = x;
                    }
                    else
                    {
                        left += x;
                    }
                    float top = ((float)this.Height - size.Height) / 2;
                    if (top < 0)
                    {
                        top = y;
                    }
                    else
                    {
                        top += y;
                    }
                    float width  = this.Width > size.Width ? size.Width : this.Width;
                    float height = this.Height > size.Height ? size.Height : this.Height;
                    ca.Graphics.DrawString(ErrorText, this.Font, Brushes.Red, new RectangleF(left, top, width, height));
                }
            }
            finally
            {
                if (null != _QRCodeControl)
                {
                    _QRCodeControl.Dispose();
                    _QRCodeControl = null;
                }
            }
            if (null != Border)
            {
                Border.DirectDraw(ca, x, y, dpiZoom);
            }
        }