FAQ TBarCode OCX
Crystal Reports 8 中的条码
Crystal Reports 8 中的条码
无法将 TBarCode 直接添加到报表中,但您可以“即时”创建条码图像并将其加载到图片框中。请按照以下说明了解如何将 TBarCode 嵌入 Crystal Reports 8。
通过图片框嵌入(VB6 示例)
在名为“Form1”的窗体中嵌入一个名为“tbc”的 TBarCode 控件和一个名为“TmpPicture1”的图片框。然后将以下函数代码添加到该窗体中。它会“即时”创建条码图像,并使用图片框作为绘图面。
Public Function BarcodeGenerate(Id As String, Width As Long, Height As Long) As PictureBox
Dim nSizing, cm
tbc.Text = Id
cm = tbc.CountModules
TmpPicture1.Cls
TmpPicture1.ScaleMode = vbPixels
Form1.ScaleMode = vbPixels
Width = ScaleX(Width, vbTwips, vbPixels)
Height = ScaleY(Height, vbTwips, vbPixels)
nSizing = Int(Width / cm)
If nSizing < 1 Then nSizing = 1
TmpPicture1.Width = cm * nSizing
TmpPicture1.Height = Height
DoEvents
tbc.BCDraw TmpPicture1.hDC, 0, 0, TmpPicture1.Width, TmpPicture1.Height
Set BarcodeGenerate = TmpPicture1
End Function
在报表事件代码(Format 事件)中调用条码生成函数,并将新创建的条码图像分配给报表中名为 Picture1 的图片框。
Private Sub Section3_Format(ByVal pFormattingInfo As Object)
'create the barcode for each record set
Dim data As String
data = Field1.Value
Set Me.Picture1.FormattedPicture =
Form1.BarcodeGenerate(data, Me.Picture1.Width, Me.Picture1.Height).Image
End Sub
通过位图文件嵌入(VB6 示例)
在名为“Form1”的窗体中嵌入一个名为“TBarCode”的 TBarCode 控件,并根据需要调整条码类型及其他所有设置。该条码对象将在报表运行时用于“即时”生成条码。
在报表事件代码(Format 事件)中,于临时文件夹中创建动态条码图像,并将该图像加载到报表中名为 pictBarCode 的图片框中。
Private Sub Section3_Format(ByVal pFormattingInfo As Object)
' Simulate data binding
' by saving the barcode as bitmap with data from fldArticleID
' then reload it to a picture control
On Error Resume Next
Dim nWidth
Dim path
Dim fso
' here we use hard coded temp path (must exist!)
path = "c:\temp\CR8_" & Me.fldArticleID.Value & ".bmp"
' reference the TBarCode Control in the Form1
Form1.TBarCode.Text = Me.fldArticleID.Value
Form1.TBarCode.PrintDataText = False
nWidth = Form1.TBarCode.CountModules * 3 'adapt width to number of graphical modules
Form1.TBarCode.SaveImage path, eIMBmp, nWidth, 100, 96, 96
Me.pictBarcode.SetOleLocation (path)
End Sub
如果您不想在窗体上添加条码控件,也可以在内存中创建一个 TBarCode 实例,并以编程方式应用相关设置。
在较新版本的 Crystal Reports 中,您可以从 URL 加载条码图像。有关此方法,请查看随 TBarCode SDK 一同安装的条码服务(samples 文件夹)。