FAQ TBarCode .NET
Как добавить дополнительный текст к элементу управления?
Как добавить дополнительный текст к элементу управления?
Это возможно, изменив активный индекс текста программно. Следующий пример кода предполагает элемент управления Barcode Control, отрисовываемый на Graphics (gfx) в пиксельных единицах, и показывает, как добавить дополнительный текст справа.
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;
Область текста #1 может быть установлена на любой текст, а также на данные вашего штрихкода. Вам нужно учитывать размеры и центрировать/выравнивать текст с помощью собственных координат.