条形码控件TBarCode SDK系列教程五(TBarCode OCX篇)

本系列教程会解答您在使用条形码生成控件TBarCode SDK产品时遇到的绝大部分疑惑。

TBarCode SDK是一款可以在任意应用程序和打印机下生成和打印所有条码的条码软件组件。TBarCode SDK对于MicrosoftOffice 用户以及软件开发者提供条码打印。使用此款条码软件组件您可以以完美效果生成和打印所有用于工业和商业条码符号。

TBarCode SDK最新版下载

一. 如何在Word VBA中以编程方式添加条形码控件/strong>

示例代码:

    Dim barcodeShape As InlineShape    ' switch to design mode (optional)    ' ActiveDocument.ToggleFormsDesign     ' Insert bar code object at actual position in document    Set barcodeShape = Selection.InlineShapes.AddOLEControl(ClassType:="TBarCode10.TBarCode10.1")    ' change size    barcodeShape.Width = 200    barcodeShape.Height = 100    ' adjust bar code properties programmatically    barcodeShape.OLEFormat.Object.Barcode = 20    ' 20 = Code-128    barcodeShape.OLEFormat.Object.Text = "Hello"

“AddOLEControl”函数接受第二个参数,该参数可以是放置条形码控件的Range对象。

二. 如何生成优化的PDF417位图图像/strong>

请使用此代码段作为起点:

Barcode.Barcode = eBC_PDF417Barcode.Text = "My Data... "' the following settings produce a barcode 82,296 mm wide' if your barcode should have a constant width, set the data columns' as shown below (increase/decrease to make wider/smaller symbol)Barcode.PDF417.Columns = 15Dim X, YDim ScalingDim Dpi' define ratio of module width (small bar width) to row heightX = 1Y = 1       ' keeps default ratio, which is 1:3'Y = 3 / 2  ' creates 1:5 ratioDpi = 300     ' 300 dpi printerScaling = 3   ' 1 Module (smallest bar) = 3 Pixels = 0.254mmDim ColsDim RowsCols = Barcode.Get2DXCols()Rows = Barcode.Get2DXRows()Dim XSizeDim YSizeXSize = Int(X * Cols)YSize = Int(Y * Rows)   ' scale with DPI enlarging factorXSize = XSize * ScalingYSize = YSize * Scaling' Save barcode as bitmapBarcode.SaveImage "c:tempbarcode.bmp", eIMBmp, XSize, YSize, Dpi, Dpi

三. 已将TBarCode添加到我的Word 2003文档中,无法保护我的Word文档/strong>

必须离开设计模式才能保护文档。如果插入条形码控件,则文档将切换到设计模式。通过Control Toolbox您可以离开设计模式,然后您就可以保护文档。

四. 如何使用CopyToClipboard在Excel VBA中生成数据矩阵/strong>

请使用此代码段作为起点:

Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long)  As LongPrivate Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongDim obj As New TBarCode10Dim nWidth As LongDim nHeight As LongDim dc As Long  With obj    .BarCode = eBC_DataMatrix    .DataMatrix.Size = eDMSz_32x32    .Text = myData    .QuietZoneUnit = eMUModules    .QuietZoneBottom = 2    .QuietZoneLeft = 2    .QuietZoneTop = 2    .QuietZoneRight = 2    .ModuleWidth = "508"    .SizeMode = eSizeMode_CustomModuleWidth    .Dpi = 1440 / Screen.TwipsPerPixelX ' screen resolution in dpi    dc = CreateCompatibleDC(0) ' screen DC    nWidth = .BCWidthHdc(dc, 96, 96, eMUPixel) + 0.9999   ' module width should be set    nHeight = .BCHeightHdc(dc, 96, 96, eMUPixel) + 0.9999 ' module width should be set    .CopyToClipboardEx dc, nWidth, nHeight, ""    DeleteDC(dc)  End With

五. 通过VBA打印:条形码未更新/strong>

您可以更改链接单元格或条形码控件的内容,然后直接从VBA中打印。但是你看到条形码控件仍然包含旧值。原因是Excel在打印之前不会向ActiveX控件发送重绘命令(如果在VBA中完成)。这是Excel中的错误。

有一种强制重绘对象的解决方法,您需要在VBA中以编程方式处理每个条形码ActiveX控件并在打印前更改其大小。然后由Excel重新绘制。

'redraw a single barcode object by adressing it through its instance nameDim origValueorigValue = TBarCode101.WidthTBarCode101.Width = origValue + 1TBarCode101.Width = origValue
' redraw all ActiveX Controls on the current sheetSub UpdateOLEControls()Dim myShape As shapeDim counter As IntegerDim origWidth As SingleFor counter = 1 To ActiveSheet.Shapes.Count  Set myShape = ActiveSheet.Shapes(counter)  If (myShape.Type = msoOLEControlObject) Then    ' resize => force redraw    origWidth = myShape.Width    myShape.Width = origWidth + 1    myShape.Width = origWidth  End IfNext counterEnd Sub

六. 如何在GS1条形码中编码FNC1/strong>

要将功能字符FNC1添加到条形码数据,请按以下步骤操作:

  1. 输入条形码数据“10222333 F 15100701”。
  2. 切换到“Settings”选项卡并检查Escape Sequences。
  3. 将插入FNC1并在HRT中自动识别应用程序标识符(AI = 15)。
  4. 在Barcode Studio 11.5+中,您可以使用新的GS1应用程序标识助手。

标签:条形码条形码生成工业4.0工业物联网

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年9月19日
下一篇 2018年9月19日

相关推荐

发表回复

登录后才能评论