Sample Code: Change Label Height From Vb.net S’abonner

0
Avatar
Shotaro Ito

Hi there,
I've got question about how to create a format which has variable length and multiple rows text. (using continuous paper, cut after each label.)
At the bottom of the label, have a barcode.

BarTender 9.4 has new feature of Rich text control. By specifying HTML source, you can create variable height HTML format text.
From ActiveX you can specify length of paper, to change label dimension depends on the height of the Rich text object.
From BarTender 9.3, you can modify object property, such as move Barcode to the bottom of label.
So I've created a test code to check if it actually works.

I know the most challenging part is how to generate HTML code programmably, but I left that for you guys :)

The project would work on VB.net 2005 and above, with BarTender 9.4 Automation (or Valid trial) required.
To specify printer, you can modify HTMLTest.btw format(or you can do that in source code.)

Hope that helps!
[attachment=10:HTMLTest.png]
[attachment=9:HTMLTest.zip]

[code]'Sample activeX application to demonstrate dynamically change label height from ActiveX
'depends on height of Rich Text object.
'
'Required BarTender 9.4 Automation or above (would work in Trial period)
'Required to add BarTender 9.40 COM reference to this project
Public Class Form1

Dim btApp As BarTender.Application
Dim btFormat As BarTender.Format

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'run BarTender
btApp = New BarTender.Application()

'open a format in current folder
btFormat = btApp.Formats.Open(Application.StartupPath & "\HTMLTest.btw", True, "")

'set unit to mm
btFormat.MeasurementUnits = BarTender.BtUnits.btUnitsMillimeters

'specify printer. if not, printer specified in format is used.
'btFormat.Printer = "Zebra Zebra TLP3844-Z"

'enable cutter for each page
'btFormat.PageSetup.MediaHandling.Action = BarTender.BtMediaHandlingAction.btMHCut
'btFormat.PageSetup.MediaHandling.Occurrence = BarTender.BtMediaHandlingOccurrence.btMHAfterEveryPage

End Sub


Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
'close format
btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges)

'quit BarTender
btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'set value to named substring
btFormat.SetNamedSubStringValue("HTMLDATA", Me.TbxHTML.Text)
btFormat.SetNamedSubStringValue("BCDATA", Me.TbxBCDATA.Text)

'adjust paper height to accomodate rich text object
Dim rHeight As Integer
rHeight = btFormat.Objects.Find("RTF1").Height
btFormat.PageSetup.PaperHeight = rHeight + 20

'move barcode to the bottom of the label
btFormat.Objects.Find("BC1").Y = btFormat.PageSetup.LabelHeight - 10

'show updated design view on dialog
Dim tempfile As String
tempfile = System.IO.Path.GetTempFileName()
btFormat.ExportToFile(tempfile, "PNG", BarTender.BtColors.btColors24Bit, BarTender.BtResolution.btResolutionScreen, BarTender.BtSaveOptions.btSaveChanges)
If System.IO.File.Exists(tempfile) Then
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(tempfile, IO.FileMode.Open, IO.FileAccess.Read)
Me.PictureBox1.Image = System.Drawing.Image.FromStream(fs)
fs.Close()
System.IO.File.Delete(tempfile)
End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Print format
btFormat.PrintOut(False, False)

End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
'show running BarTender application
If Me.CheckBox1.Checked Then
btApp.VisibleWindows = BarTender.BtVisibleWindows.btAll
Else
btApp.VisibleWindows = BarTender.BtVisibleWindows.btNone
End If
End Sub
End Class[/code]

Veuillez vous connecter pour laisser un commentaire.