C#调用把BarTender模板

// Change the number of identical labels and serialized labels to print btFormat.PrintSetup.NumberOfSerializedLabels = 4; btFormat.PrintSetup.IdenticalCopiesOfLabel = 10; // Print the label

Resultresult = btFormat.Print(); } In VB:

' Initialize and start a new engine UsingbtEngineAs NewEngine() btEngine.Start() ' Open a label format.

DimbtFormatAsLabelFormatDocument =

btEngine.Documents.Open(\)

' Change the number of identical labels and serialized labels to print btFormat.PrintSetup.NumberOfSerializedLabels = 4 btFormat.PrintSetup.IdenticalCopiesOfLabel = 10 ' Print the label

Dim result As Result = btFormat.Print() End Using

In the above example, a new Engine instance is started and a label format is opened in that Engine instance. The number of serialized labels and identical copies is changed, and the label is printed.

Printing to a Different Printer

Selecting a printer to print label formats can be accomplished in two different ways:

?

Specifying the printer when opening a label format

?

Setting the LabelFormatDocument object's PrinterName property

The following code demonstrates opening a label format using the default printer, and opening a label format using a specific printer. In C#:

// Initialize and start a new engine using (EnginebtEngine = newEngine()) {

btEngine.Start();

// Open a label format specifying the default printer LabelFormatDocumentbtFormat =

btEngine.Documents.Open(@\); // Print the label

Resultresult = btFormat.Print(\);

// Open a label format specifying a different printer btFormat = btEngine.Documents.Open(@\, \); // Print the label

result = btFormat.Print(); } In VB:

' Initialize and start a new engine UsingbtEngineAs NewEngine() btEngine.Start()

' Open a label format specifying the default printer DimbtFormatAsLabelFormatDocument =

btEngine.Documents.Open(\) ' Print the label

Dim result As Result = btFormat.Print(\) ' Open a label format specifying a different printer btFormat = btEngine.Documents.Open(\, \) ' Print the label

result = btFormat.Print() End Using

In the above example, a new Engine instance is created and started. The label file MyLabel1.btw is opened and will print using the printer the label format was saved with. The label file MyLabel2.btw will print to the specified printer (OurPrinter_HX3000).

Alternately, the printer name may be changed once the label format is already open. This is accomplished by changing the

LabelFormatDocument'sPrintSetup.PrinterName property.

The following code demonstrates how to change the printer the label format will use to print. In C#:

// Initialize and start a new engine using (EnginebtEngine = newEngine()) {

btEngine.Start();

// Open a label format specifying the default printer LabelFormatDocumentbtFormat =

btEngine.Documents.Open(@\); // Change the name of the printer

btFormat.PrintSetup.PrinterName = @\; // Print the label

Resultresult = btFormat.Print(); }

In VB:

' Initialize and start a new engine UsingbtEngineAs NewEngine() btEngine.Start()

' Open a label format specifying the default printer DimbtFormatAsLabelFormatDocument =

btEngine.Documents.Open(\) ' Change the name of the printer

btFormat.PrintSetup.PrinterName = \ ' Print the label

Dim result As Result = btFormat.Print() End Using

In the above example, a new Engine instance is started and a label format is opened in that Engine instance. The name of the printer is changed before the label prints.

Printing and Print Job Events

The progress of a print job can be monitored by utilizing print job events. The LabelFormatDocument class contains delegates defining different events that can occur during printing. By creating and hooking up event handlers to these delegates, the progress of a print job can be tracked. For more information, refer to Working with Print Job Status Events.

Changing Text and Barcode Data on the Label Format

Label formats may contain named substrings, denoting fields on a label that may be changed. Typically, each substring represents a complete text object, barcode, or RFID tag on a label, although some objects may have more that one substring. By changing the values of these substrings, you

can change the information printed on a label. For more information on how to define substrings on a label, see BarTender's application help.

Reading Named Substrings

Each LabelFormatDocument object contains a Substrings collection. This collection stores a list of all named substrings that are part of a label. The following code demonstrates how to read named substrings. In C#:

EnginebtEngine = newEngine();

LabelFormatDocumentbtFormat =

btEngine.Documents.Open(@\);

stringAddressSubstring = btFormat.SubStrings[\].Value; In VB:

DimbtEngineAs NewEngine()

DimbtFormatAsLabelFormatDocument =

btEngine.Documents.Open(\)

DimAddressSubstringAs String = btFormat.SubStrings(\).Value The above code reads substrings that are explicitly part of the MyLabel label format. These named substrings are specific to MyLabel and might not exist in other label formats. The BarTender Print SDK throws an exception if an attempt is made to access a nonexistent substring.

Modifying Named Substrings

Named substrings not only can be read, but they can be modified

programmatically. The following code demonstrates how to modify named substrings. In C#:

EnginebtEngine = newEngine();

LabelFormatDocumentbtFormat =

btEngine.Documents.Open(@\);

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4