Preguntas frecuentes sobre TBarCode .NET
¿Cómo puedo añadir texto adicional al control?
¿Cómo puedo añadir texto adicional al control?
Esto es posible cambiando el índice de texto activo mediante programación. El siguiente código de ejemplo supone un control de código de barras dibujado sobre un objeto Graphics (gfx) en unidades de píxel, y muestra cómo añadir texto adicional en el lado derecho.
Barcode tbc = barcodeControl1.Barcode;
Graphics gfx = this.CreateGraphics();
SizeF barcodeSizeMM = tbc.CalculateBarcodeSize(gfx);
double pixelSizeMM = 25.4F / gfx.DpiX;
int barcodeWidthPx = Convert.ToInt32(0.5 + barcodeSizeMM.Width / pixelSizeMM);
int barcodeHeightPx = Convert.ToInt32(0.5 + barcodeSizeMM.Height / pixelSizeMM);
// first add a quiet zone for our text area
tbc.QuietZones.Right.Size = 100;
tbc.QuietZones.Unit = QuietZoneUnit.Pixel;
// set barcode data (+ normal HRT) in text area #0
tbc.ActiveTextIndex = 0;
tbc.BarcodeType = BarcodeType.Code128;
tbc.Data = "1234567890";
tbc.IsTextVisible = false;
// change text index to (auxiliary) text area #1
tbc.ActiveTextIndex = 1;
// now adjust all settings for text area #1
tbc.HumanReadableText ="My Label Text";
tbc.Font = new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point);
tbc.TextClipping = false;
tbc.IsTextVisible = true;
tbc.TextPositionTop = (barcodeHeightPx - (int) tbc.Font.GetHeight(gfx)) / 2 ;
tbc.TextPositionLeft = barcodeWidthPx - (int)tbc.QuietZones.Right.Size + 10;
// reset text index back to barcode text
tbc.ActiveTextIndex = 0;
El área de texto n.º 1 se puede configurar con cualquier texto, pero también con los datos de su código de barras. Debe cuidar las dimensiones y necesita centrar/alinear el texto con sus propias coordenadas.