




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、应用“ Seagull.BarTender.Print “命名空间,2、代码如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;/using System.Threading.Tasks;using System.Windows.Forms;using Seagull.BarTender.Print;/using Seagull.BarTender;namespace BarTenderPrintTest1 public partial class Form1 : Form public Form1() InitializeComponent(); /Bar string dc = D:lipingBartenderPrintBarTenderPrintTest1BarTenderPrintTest1binDebugHW_CaiHe_and_packbox.btw; int ff = 163704004; string aa = 00057616-; int i = 1; private void btn_print_Click(object sender, EventArgs e) PrintLabel3(); #region 第一种写法 private void PrintLabel1() /创建一个BarTender打印引擎 ,并启用 Engine engine = new Engine(true); /创建一个模板对象 /LabelFormatDocument format = engine.Documents.Open(c:test.btw); LabelFormatDocument format = engine.Documents.Open(D:lipingBartenderPrintBarTenderPrintTest1BarTenderPrintTest1binDebugHW_CaiHe_and_packbox.btw); format.Print(print me label); /format.Print(Select printer, out messages); /format.Close(SaveOptions.SaveChanges ); format.Print(); engine.Dispose(); #endregion #region 打印第二种方法 private void PrintLable2() using (Engine engine = new Engine() /启用一个打印引擎 engine.Start(); /创建一个模板对象 LabelFormatDocument format = engine.Documents.Open(D:lipingBartenderPrintBarTenderPrintTest1BarTenderPrintTest1binDebugHW_CaiHe_and_packbox.btw); /打印 /format.Print(print me label); /改变标签打印数份连载 format.PrintSetup.NumberOfSerializedLabels =1; /设定印标签打印数量 format.PrintSetup.IdenticalCopiesOfLabel = 1; Result nResult = format.Print(); /指定打印机打印,不指定则使用默认打印机 format.PrintSetup.PrinterName = Bar Code Printer T-4503E; / Display the print result. /Console.WriteLine(Print status = + nResult); MessageBox.Show(打印提示:+nResult ); / Close the current format without saving. /SaveOptions 有三个值 DoNotSaveChanges:不保存 ,PromptSave:提示是否保存 SaveChanges:保存 format.Close(SaveOptions.DoNotSaveChanges); /结束打印引擎 engine.Stop(); #endregion #region 第三种打印方法改变标签的值 private void PrintLabel3() using (Engine engine = new Engine(true) LabelFormatDocument btFormat = engine.Documents.Open(dc); /MessageBox.Show(btFormat.SubStrings0.Name); /获取标签的值 /string AddressSubstring = btFormat.SubStringsHWbarcode1.Value; /MessageBox.Show(AddressSubstring); /修改标签的值 /btFormat.SubStringsAddress.Value = 1313 Mockingbird Lane, Anywhere, USA; /btFormat.SubStringsName.Value = John Doe; /btFormat.SubStringsQuantity.Value = 10; int dd = ff + i; i+; btFormat.SubStringsHWbarcode1.Value = aa+dd.ToString (); /改变标签打印数份连载 btFormat.PrintSetup.NumberOfSerializedLabels = 1; /设定印标签打印数量 btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; Result nResult = btFormat.Print(); /指定打印机打印,不指定则使用默认打印机 btFormat.PrintSetup.PrinterName = Bar Code Printer T-4503E; MessageBox.Show(打印提示: + nResult); btFormat.Close(SaveOptions.DoNotSaveChanges); /结束打印引擎 engine.Stop(); #endregion 三、bartender 说明文档部分Creating a BarTender Print EngineThe Engine class represents a BarTender process and provides the backbone for programming with the BarTender Print SDK. All programs written with the BarTender Print SDK will rely on the Engine class to provide BarTender print functionality. The BarTender Print EngineThe BarTender process (bartend.exe) provides standard BarTender functionality, such as opening label formats, changing label settings, and printing. The BarTender background process is controlled using an instance of the Engine class. The Role of the Engine ClassThe Engine class contains many methods, properties, and events to assist in printing and controlling the BarTender Print Engine. Features of the Engine ClassThe Engine class allows users to: Start, stop, and restart a BarTender background process. Open, access, and save label formats. Use Engine-level events to monitor printing. Manage the BarTender Application window.How To: Start and Stop an EngineAn engine must be created and started in order to launch a BarTender process and commence printing. The Engine class provides the Engine.Stop method to explicitly shut down the BarTender Print Engine. If the engine is not stopped, a bartend.exe process may be left running in the background. After calling the Engine.Stop method, it is best practice to call the Engine.Dispose method. The Dispose method ensures all non-memory resources are properly released for the class; this includes shutting down the BarTender process if Engine.Stop was not successfully called. The following is the minimal code necessary to create, start, stop, and dispose an Engine object: In C#:/ Calling constructor with true automatically starts engine. using (Engine btEngine = new Engine(true) / Do something with the engine. / Stop the BarTender process. btEngine.Stop(); In VB: Calling constructor with true automatically starts engine. Using btEngine As New Engine(True) Do something with the engine. Stop the BarTender process. btEngine.Stop() End Using In the above example, an engine is created and started implicitly by passing true as an argument to the constructor. The engine is then stopped by calling the Engine.Stop method. This terminates the background bartend.exe process. Finally, Engine.Dispose is called automatically when execution leaves the using statement, releasing all Engine resources. It is also possible to start the engine explicitly after it has been created using the default Engine constructor and the Engine.Start method. By default, Engine.Stop will close all open formats without saving, but an overloaded version is provided that allows manual control. The following example shows alternative code for starting and stopping an engine and saving changes:In C#:using (Engine btEngine = new Engine() / Application specific code / Explicitly start the engine btEngine.Start();/ Application-specific code / Assuming the application wants to save changes, /it can be easily done at Stop time. btEngine.Stop(SaveOptions.SaveChanges); In VB:Using btEngine As New Engine(True) Application specific code Explicitly start the engine btEngine.Start() Application-specific code Assuming the application wants to save changes, it can be easily done at Stop time. btEngine.Stop(SaveOptions.SaveChanges) End Using In the above example, a new Engine is created, but not started until later. Some application activity is assumed to execute, then the Stop method is called. In this case, changes to labels done while using the engine are saved back to file. The SaveOptions enumeration specifies the operation concerning open label formats to perform during exit of BarTender. In the above examples and many other examples in this document, the Engine.Dispose method is called implicitly by a using statement. While it is not always appropriate to utilize using, it is a convenient way to ensure Dispose is called even if the block is exited during an exception. How To: Use Engine as a Field in a ClassThe above examples, and most examples in this document, present use of an Engine instance in a single method. This approach is not practical for most real applications. Starting and stopping Engine objects, and by extension BarTender processes, should be done as rarely as possible for optimal performance. Ideally, Engine instances should be started once and only stopped at the end of the application to minimize the overhead of managing processes. The most straightforward object-oriented approach is make an Engine object a field in a class and allow the encapsulating class to determine the Engine objects lifetime. The following is the minimal suggested code for making an Engine object a field in a class:In C#:public class EngineWrapper : IDisposable / Engine Field private Engine m_engine = null;/ This property will create and start the engine the first time it is / called. Most methods in this class (and methods in child classes) / should utilize this property instead of the m_engine field. protected Engine BtEngine get / If the engine has not been created yet, create and start it. if (m_engine = null) m_engine = new Engine(true); return m_engine; / Implement IDisposable public void Dispose() / The engine only needs to be stopped and disposed if it was / created. Use the field here, not the property. Otherwise, / you might create a new instance in the Dispose method! if (m_engine != null) / Stop the process and release Engine field resources. m_engine.Stop(); m_engine.Dispose(); / Additional methods for specific work in your application. All additional / methods should use the BtEngine property instead of the m_engine field. In VB:Public Class EngineWrapper Implements IDisposable Engine Field Private m_engine As Engine = Nothing This property will create and start the engine the first time it is called. Most methods in this class (and methods in child classes) should utilize this property instead of the m_engine field. Protected ReadOnly Property BtEngine() As Engine Get If the engine has not been created yet, create and start it. If m_engine Is Nothing Thenm_engine = New Engine(True) End If Return m_engine End Get End Property Implement IDisposable Public Sub Dispose() Implements IDisposable.Dispose The engine only needs to be stopped and disposed if it was created. Use the field here, not the property. Otherwise, you might create a new instance in the Dispose method! If m_engine IsNot Nothing Then Stop the process and release Engine field resources. m_engine.Stop() m_engine.Dispose() End If End Sub Additional methods for specific work in your application. All additional methods should use the BtEngine property instead of the m_engine field. End Class The class above provides lazy instantiation of an Engine object and a method for disposal of its resources. By using the BtEngine property for all work in its methods, this class will avoid creating and starting a BarTender process until it really needs one. This class offers a means of releasing its resources, its underlying Engine object, by implementing the IDisposable interface. If this class were used in a real application, it would include other methods that did work specific to the application. This code would be a reasonable base class for a hierarchy of classes that perform printing in a real application. In the case where instances of this class are intended to be used from multiple threads in an application, locking logic should be added to the BtEngine property to ensure the engine is only created once. How To: Display the BarTender User InterfaceBy default, an Engine objects BarTender process runs BarTender in the background without being seen by a user. However, there may be times you will want to view and interact with BarTender抯 user interface. The following example shows how to view BarTender抯 users interface using the Engine.Window.Visible property. In C#:using (Engine btEngine = new Engine() btEngine.Start(); btEngine.Window.Visible = true;/ Application-specific code btEngine.Stop(); In VB:Using btEngine As New Engine() btEngine.Start() btEngine.Window.Visible = True Application-specific code btEngine.Stop() End Using In the above code, a new Engine is initialized and started. The BarTender application window is then shown by setting the Engine.Windows Visible property to true. The method assumes some intervening work is done. Finally, the engine is stopped and automatically disposed when leaving the using statement. If this code is run without any intervening work between the call to btEngine.Window.Visible and the btEngine.Stop method, the BarTender window will only flash open for a moment, then immediately close when the engine is stopped and the BarTender process is shutdown. The Engine Class and Print Job EventsThe Engine class provides many engine-wide events. Most of these, such as the JobQueued or JobSent, are used to monitor the status of a print job. These same events are found in the LabelFormatDocument class, where they are specific to that label format. Unlike the events found in LabelFormatDocument, Engine events provide a means to oversee print job events for all label formats opened by the engine. For more information, refer to Working with Print Job Status Events.Printing Label FormatsA label format can be printed by calling the LabelFormatDocuments Print method. The Print method prints a job to a printers spooler and returns a Result enumeration value. It can either return immediately after spooling the print job or wait to return until printing is complete. The LabelFormatDocument object contains several overloads for the Print method to assist in label printing. Print() Print(string printJobName) Print(string printJobName, out Messages message) Print(string printJobName, int waitForCompletionTimeout) Print(string printJobName, int waitForCompletionTimeout, out Messages messages) Using the Print MethodSeveral Print overloads exist; the simplest takes no parameters. The following code shows how to open and print a label format. In C#:LabelFormatDocument btFormat = btEngine.Documents.Open(c:MyLabel.btw);Result result = btFormat.Print(); In VB:Dim btFormat As LabelFormatDocument = btEngine.Documents.Open(c:MyLabel.btw)Dim result As Result = btFormat.Print() When this method is called, a Result enumeration is immediately returned. A value of Success indicates that the print job successfully spooled to the printer; a value of Failure indicates otherwise. The Print method specifies the name of the print job, a flag indicating whether to wait for the print job to complete or not, and a collection of messages. The following code shows how to print a format that is open in the BarTender print engine. In C#:Messages messages = null;LabelFormatDocument btFormat = btEngine.Documents.Open(c:MyLabel.btw);Result result = btFormat.Print(PrintJob1, out messages); In VB:Dim messages As Messages = NothingDim btFormat As LabelFormatDocument = btEngine.Documents.Open(c:MyLabel.btw)Dim result As Result = btFormat.Print(PrintJob1, messages) In the above example, the application will immediately resume after the Print method call. In instances where many print jobs are being spooled, an errant print job might delay further printing. In this case it is appropriate to specify a timeout length before the program resumes. If the second parameter is passed as true, then the third parameter indicates the timeout length. Since the second parameter is passed as false, the timeout parameter should always be set to zero. If the print job is successfully spooled, the method will immediately return with a Success Result value. The Result variable stores the results of the print job, indicating whether the print job has succeeded or failed. Result can indicate the print job has succeeded, timed out, or failed for a variety of reasons. If the result indicates the print job was not successful, the messages collection contains messages indicating any errors BarTender encountered. The Messages CollectionWhile printing, one or more messages may be generated indicating print success or error. These messages can be viewed by enumerating the Messages collection returned as a parameter from the Print method. Each Message object in the collection contains a Text property giving a description of the message. The message severity and type can be examined by using the Severity and Type properties, respectively. Printing Multiple FormatsThe Engine class contains a collection of LabelFormatDocument objects that are opened within the BarTender print engine. By looping through this collection, it is possible to print many format files at once. The following code demonstrates a method for printing multiple formats.In C#:int i = 0;foreach (LabelFormatDocument format in btEngine.Documents) i+; format.Print(PrintJob + i); In VB:Dim i As Integer = 0For Each format As LabelFormatDocument In btEngine.Documents i += 1 format.Print(PrintJob & i) Next format Every format that is opened in BarTender will be printed and given a print job name corresponding to the order in which it was printed. Changing the Number of Copies to PrintPrinting identical copies of a label or printing serialized copies of a label is common when printing barcode labels. To chan
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年药师考试高级辅助用药试题及答案
- 2025年即将到来的语文考试试题及答案
- 地方文化保护与地方经济发展的关系试题及答案
- 行政管理专业的语文学习方法试题及答案
- 2025卫生资格考试重要知识点试题及答案
- 主管护师考试时间管理技巧与试题及答案
- 大学语文考试实践类型题目及答案(2025年)
- 行政管理专科流程优化路径试题及答案
- 护理责任与权利的平衡2025年试题及答案
- 地方历史文化在政策制定中的作用试题及答案
- 办公场地租赁合同示范文本
- 水利工程档案管理简单培训
- 社区文艺汇演服务合同(2篇)
- 中国慢性冠脉综合征患者诊断及管理指南2024版解读
- 活跃课堂气氛+激发学习兴趣
- 基于区块链技术的供应链管理平台构建
- 家居安全监测报警系统答辩
- 心梗的预防指南
- 四川省护理质量管理评价标准
- DB33T 2320-2021 工业集聚区社区化管理和服务规范
- 乡村公路施工合同
评论
0/150
提交评论