FAQ TBarCode OCX
如何向控件添加额外的文本行?
如何向控件添加额外的文本行?
可以通过编程方式更改活动文本索引来实现这一点。以下是一个 Excel VBA 示例。TBarCode111 是工作表上 TBarCode 实例的名称。
' first add a quiet zone for our text area TBarCode111.QuietZoneTop = 10 TBarCode111.QuietZoneUnit = eMUMM ' set barcode data (+ normal HRT) in text area #0 TBarCode111.ActiveTextIndex = 0 TBarCode111.BarCode = eBC_Code128 TBarCode111.Text = "1234567890" TBarCode111.DisplayText = "" Dim fontBarcode As New stdole.StdFont fontBarcode.Name = "Arial" fontBarcode.Size = 12 TBarCode111.font = fontBarcode ' change text index to (auxiliary) text area #1 TBarCode111.ActiveTextIndex = 1 ' now adjust all settings for text area #1 TBarCode111.DisplayText = "My Label Text" TBarCode111.TextPositionLeft = 0 TBarCode111.TextPositionTop = 0 TBarCode111.TextClipping = False TBarCode111.PrintDataText = True Dim fontLabel As New stdole.StdFont fontLabel.Name = "Arial" fontLabel.Size = 10 fontLabel.Weight = 800 TBarCode111.font = fontLabel ' reset text index back to barcode text TBarCode111.ActiveTextIndex = 0
带文本标签的二维码®
以下是使用 Excel VBA 创建二维码的示例。
Dim BarcodeImageWidth As Long Dim BarcodeImageHeight As Long Dim BarcodeImageDPI Dim ImageScaling BarcodeImageDPI = 300 ImageScaling = 3 With bcTBarCode111 .BarCode = eBC_QRCode .QRCode.ECLevel = eQREC_Medium .Quality = 100 .SuppressErrorMsg = False .ActiveTextIndex = 0 .Text = "SERIAL00001" .QuietZoneBottom = 6 .QuietZoneLeft = 2 .QuietZoneRight = 2 .QuietZoneUnit = eMUModules .Dpi = BarcodeImageDPI End With bcTBarCode111.GetOptimalBitmapSize ImageScaling, ImageScaling, BarcodeImageWidth, BarcodeImageHeight Dim fontBarcodeLabel As New stdole.StdFont fontBarcodeLabel.Name = "Arial" fontBarcodeLabel.Size = 8 fontBarcodeLabel.Weight = 800 Dim PixelPerModule Dim CountVerticalModules CountVerticalModules = bcTBarCode111.Get2DXRows() + bcTBarCode111.QuietZoneBottom PixelPerModule = BarcodeImageHeight / CountVerticalModules With bcTBarCode111 ' change text index to (auxiliary) text area #1 .ActiveTextIndex = 1 ' now adjust all settings for text area #1 .DisplayText = .Text .TextPositionLeft = BarcodeImageWidth / 2 .TextPositionTop = BarcodeImageHeight - (PixelPerModule * (.QuietZoneBottom - 1)) .TextAlignment = eAlCenter .TextClipping = False .PrintDataText = True .Font = fontBarcodeLabel ' reset text index back to barcode text .ActiveTextIndex = 0 End With bcTBarCode111.SaveImage sFileName:="C:\Temp\SERIAL 00001.png", eImageType:=eIMPng, _ nXSize:=BarcodeImageWidth, nYSize:=BarcodeImageHeight, _ dXRes:=BarcodeImageDPI, dYRes:=BarcodeImageDPI