版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、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.BarTen
2、der;namespace BarTenderPrintTest1 public partial class Form1 : Form public Form1() InitializeComponent(); &
3、#160; /Bar string dc = "D:lipingBartenderPrintBarTenderPrintTest1BarTenderPrintTest1binDebugHW_CaiHe_and_packbox.btw" int ff = 163704
4、004; string aa = "00057616-" int i = 1; private void btn_print_Click(object sender, EventArgs e) &
5、#160; PrintLabel3(); #region 第一种写法 private void PrintLabel1()
6、60; /创建一个BarTender打印引擎 ,并启用 Engine engine = new Engine(true); /创建一个模板对象
7、 /LabelFormatDocument format = engine.Documents.Open("c:test.btw"); LabelFormatDocument format = engine.Documents.Open("D:lipingBartenderPrintBarTenderPrintTes
8、t1BarTenderPrintTest1binDebugHW_CaiHe_and_packbox.btw"); format.Print("print me label"); /format.Print("Select printer", out messages);
9、160; /format.Close(SaveOptions.SaveChanges ); format.Print(); engine.Dispose();
10、; #endregion #region 打印第二种方法 private void PrintLable2()
11、160; using (Engine engine = new Engine() /启用一个打印引擎
12、60; engine.Start(); /创建一个模板对象
13、 LabelFormatDocument format = engine.Documents.Open("D:lipingBartenderPrintBarTenderPrintTest1BarTenderPrintTest1binDebugHW_CaiHe_and_packbox.btw"); /打印
14、 /format.Print("print me label"); /改变标签打印数份连载
15、; format.PrintSetup.NumberOfSerializedLabels =1; /设定印标签打印数量 format.PrintSetup.IdenticalCopiesOfLabel = 1;
16、60; Result nResult = format.Print(); /指定打印机打印,不指定则使用默认打印机
17、60; format.PrintSetup.PrinterName = "Bar Code Printer T-4503E" / Display the print result. /
18、Console.WriteLine("Print status = " + nResult); MessageBox.Show("打印提示:"+nResult ); / Close the curre
19、nt format without saving. /SaveOptions 有三个值 DoNotSaveChanges:不保存 ,PromptSave:提示是否保存 SaveChanges:保存 format.Cl
20、ose(SaveOptions.DoNotSaveChanges); /结束打印引擎
21、 engine.Stop(); #endregion #region 第三种打印方法改变标签的值 pri
22、vate void PrintLabel3() using (Engine engine = new Engine(true) &
23、#160; LabelFormatDocument btFormat = engine.Documents.Open(dc); /MessageBox.Show(btFormat.SubStrings0.Name);
24、 /获取标签的值 /string AddressSubstring = btFormat.SubStrings"HWbarcode1".Value; /MessageBox.Show(Addre
25、ssSubstring); /修改标签的值 /btFormat.SubStrings"Address".Value = "1313 Mockingbird Lane, Anywhere, USA"
26、160; /btFormat.SubStrings"Name".Value = "John Doe" /btFormat.SubStrings"Quantity".Value = "
27、10" int dd = ff + i; i+;
28、 btFormat.SubStrings"HWbarcode1".Value = aa+dd.ToString (); /改变标签打印数份连载 btFormat.PrintSetup.NumberOfSerializedLabels
29、 = 1; /设定印标签打印数量 btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
30、160; Result nResult = btFormat.Print(); /指定打印机打印,不指定则使用默认打印机 btFormat.PrintSetup.PrinterNa
31、me = "Bar Code Printer T-4503E" MessageBox.Show("打印提示:" + nResult); btFormat.Close(SaveOptions.DoNot
32、SaveChanges); /结束打印引擎 engine.Stop();
33、; #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 B
34、arTender 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 i
35、s 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 restar
36、t 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 pri
37、nting. 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 Disp
38、ose 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
39、 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 some
40、thing 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 backgrou
41、nd 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.
42、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
43、 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 st
44、art 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
45、 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 o
46、ther 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 Fi
47、eld 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
48、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 dete
49、rmine the Engine object's 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 / call
50、ed. 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 IDis
51、posable 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()
52、; 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
53、 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 a
54、nd 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
55、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
56、' 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
57、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
58、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
59、 created once. How To: Display the BarTender User InterfaceBy default, an Engine object's 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 ho
60、w to view BarTender抯 users interface using the 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-spe
61、cific 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.Window's Visible property to true. The method assumes some intervening work is done. Finally, the engine is stopped and automatica
62、lly 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 BarTen
63、der 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 th
64、at 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 th
65、e LabelFormatDocument's Print method. The Print method prints a job to a printer's 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 overl
66、oads 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
67、 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 btForma
68、t 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 indic
69、ates 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;LabelF
70、ormatDocument 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 = btFo
71、rmat.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 be
72、fore 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
73、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, th
74、e 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 Pr
75、int 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.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年临沧c1客运资格证考试
- 拆迁要求市场补偿申请书
- 吉首大学《竞技武术套路3》2021-2022学年第一学期期末试卷
- 吉首大学《地理信息系统应用》2021-2022学年第一学期期末试卷
- 吉林艺术学院《影片制作》2021-2022学年第一学期期末试卷
- 吉林艺术学院《声乐基础训练Ⅱ》2021-2022学年第一学期期末试卷
- 门店充电宝签约协议书范本模板
- 吉林艺术学院《表演艺术公共文化服务》2021-2022学年第一学期期末试卷
- 吉林师范大学《招聘与甄选》2021-2022学年第一学期期末试卷
- 2024年大型饭堂采购合同范本
- 2024-2030年中国木制品行业市场深度发展趋势与前景展望战略分析报告
- 2024年新人教版部编本四年级上数学教材深度解读
- 《新时代公民道德建设实施纲要》、《新时代爱国主义教育实施纲要》知识竞赛试题库55题(含答案)
- 《追求远大理想坚定崇高信念》课件
- DL∕T 5210.4-2018 电力建设施工质量验收规程 第4部分:热工仪表及控制装置
- 2024-2025学年牛津版小学六年级英语上册期中检查试题及答案
- 酒店自助入住系统安装协议
- 集体荣誉感主题教育班会
- 金融调解中心可行性报告
- 剧院物业管理服务标准
- 《5以内的减法》幼儿园数学课件
评论
0/150
提交评论