Completed
Last Updated: 01 Jul 2019 14:37 by ADMIN
Release R3 2019 (LIB 2019.2.708)
Mark
Created on: 20 Jun 2019 14:18
Category: Barcode
Type: Bug Report
1
RadBarcode: The QRCode symbology does not center the element if it has a higher version

The issue can be reproduced by adding a RadBarCode to the form and setting its value this way:

this.radBarcode1.Value = "https://docs.telerik.com/devtools/winforms/introduction";

1 comment
ADMIN
Hristo
Posted on: 20 Jun 2019 14:22
Hello,

The issue can be worked around with a custom control this way: 
public class MyRadBarcode : RadBarcode
{
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadBarcode).FullName;
        }
    }
 
    protected override RadBarcodeElement CreateBarcodeElement()
    {
        return new MyRadBarcodeElement();
    }
}
 
public class MyRadBarcodeElement : RadBarcodeElement
{
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadBarcodeElement);
        }
    }
 
    protected override void PaintElements(IGraphics graphics, ISymbology symbology, IElementFactory elementFactory)
    {
        if (symbology as PDF417 != null)
        {
            graphics.TranslateTransform((this.Bounds.Width - elementFactory.ElementsBounds.Width) / 2f, (this.Bounds.Height - elementFactory.ElementsBounds.Height) / 2f);
        }
        else if (symbology is QRCode)
        {
            QRCode qRCode = (QRCode)symbology;
            int elementSize = Math.Min(this.Bounds.Width / qRCode.BinaryMatrix.GetLength(1), this.Bounds.Height / qRCode.BinaryMatrix.GetLength(0));
            int quietZone = TelerikDpiHelper.ScaleInt(QRCode.QuietZone, this.DpiScaleFactor) * elementSize;
            graphics.TranslateTransform(Math.Abs(this.Bounds.Width - elementFactory.ElementsBounds.Width - quietZone) / 2f, Math.Abs(this.Bounds.Height - elementFactory.ElementsBounds.Height - quietZone) / 2f);
        }
 
        (graphics.UnderlayGraphics as Graphics).Clear(this.BackColor);
 
        foreach (BarcodeElementBase element in elementFactory.Elements)
        {
            element.PaintElement(graphics.UnderlayGraphics as Graphics);
        }
    }
}

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.