FAQ TBarCode OCX
Codici a Barre in Crystal Reports 8
Codici a Barre in Crystal Reports 8
Non è possibile aggiungere TBarCode direttamente in un report, ma potete creare un’immagine di codice a barre "al volo" e caricarla in una casella immagine. Seguite le istruzioni sotto per vedere come funziona l’integrazione di TBarCode in Crystal Reports 8.
Integrazione tramite Casella Immagine (esempio VB6)
In un form (denominato “Form1”) integrate un controllo TBarCode (denominato “tbc”) e una casella immagine (denominata “TmpPicture1”). Quindi aggiungete il codice della funzione sotto al form. Crea un’immagine di codice a barre "al volo" e utilizza la PictureBox come superficie di disegno.
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
Nel codice evento del report (evento Format) richiamate la funzione generatore di codici a barre e assegnate l’immagine del codice a barre appena creata alla casella immagine (denominata Picture1) nel report.
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
Integrazione tramite File Bitmap (esempio VB6)
In un form (denominato “Form1”) integrate un controllo TBarCode (denominato “TBarCode”) e configurate il tipo di codice a barre e tutte le altre impostazioni desiderate. Questo oggetto codice a barre verrà utilizzato durante l’esecuzione del report per la creazione del codice a barre "al volo".
Nel codice evento del report (evento Format) create un’immagine di codice a barre dinamica in una cartella temporanea e caricate questa immagine nella casella immagine (denominata pictBarCode) nel report.
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
Se non desiderate aggiungere un controllo codice a barre al form, potete creare un’istanza di TBarCode anche in memoria e applicare le impostazioni a livello di programmazione.