版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1、应用“ Seagull.BarTender.Print“命名空间, using System; using System.Collectio ns.Ge neric; using System.Comp onen tModel; using System.Data; using System.Drawi ng; using System丄inq; using System.Text; /using System.Threadi ng.Tasks; using System.Wi ndows.Forms; using Seagull.BarTe nder.Pri nt; /using Sea
2、gull.BarTe nder; n amespace BarTe nderPri ntTest1 public partial class Form1 : Form public Form1() In itializeComp onen t(); /Bar string dc = D:lipingBartenderPrintBarTenderPrintTest1BarTenderPrintTest1bi nDebugHW_CaiHe_and_packbox.btw; int ff = 163704004; string aa = 00057616-; int i = 1; private v
3、oid 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 = BarTenderPrintTest1binDebugHW_
4、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(); / 创建一个模板对
5、 象 LabelFormatDocument format = BarTenderPrintTest1binDebugHW_CaiHe_and_packbox.btw); / 打印 /format.Print(print me label); / 改变标签打印数份连载 format.PrintSetup.NumberOfSerializedLa bels =1; / 设定印标签打印数量 format.PrintSetup.IdenticalCopiesOfLab el = 1; Result nResult = format.Print(); / 指定打印机打印 , 不指定则使用默认打印 机
6、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(SaveO
7、ptions.DoNotSaveChan ges); / 结束打印引擎 engine.Stop(); #endregion #region 第三种打印方法改变标签的值 private void PrintLabel3() using (Engine engine = new Engine(true) LabelFormatDocument btFormat = engine.Documents.Open(dc); /MessageBox.Show(btFormat.SubStrings 0.Name); / 获取标签的值 /string AddressSubstring = btFormat.
8、SubStringsHWbarcode1.Value; /MessageBox.Show(AddressSubstring); / 修改标签的值 /btFormat.SubStringsAddress.Value = 1313 Mockingbird Lane, Anywhere, USA; /btFormat.SubStringsName.Value = John Doe; /btFormat.SubStringsQuantity.Valu e = 10; int dd = ff + i; i+; btFormat.SubStringsHWbarcode1.Valu e = aa+dd.To
9、String (); / 改变标签打印数份连载 btFormat.PrintSetup.NumberOfSerialized Labels = 1; / 设定印标签打印数量 btFormat.PrintSetup.IdenticalCopiesOfL abel = 1; Result nResult = btFormat.Print(); / 指定打印机打印 , 不指定则使用默认打印 机 btFormat.PrintSetup.PrinterName = Bar Code Printer T-4503E; MessageBox.Show( 打印提示: + nResult); btFormat.
10、Close(SaveOptions.DoNotSaveCh anges); / 结束打印引擎 #endregion engine.Stop(); 三、bartender说明文档部分 Creating a BarTender Print Engine The Engine class represents a BarTender process and provides the backbone for program ming with the BarTe nder Print SDK. All programs writte n with the BarTender Print SDKwil
11、l rely on the Engine class to provide BarTender print function ality. The BarTe nder Print Engine The BarTe nder process (barte nd.exe) provides sta ndard BarTe nder fun cti on ality, such as ope ning label formats, cha nging label sett in gs, and prin ti ng. The BarTe nder backgro und process is co
12、n trolled using an in sta nee of the Engine class. The Role of the Engine Class The Engine class contains many methods, properties,and events to assist in printing and controlling the BarTender Print Engine. Features of the Engine Class The Engine class allows users to: Start, stop, and restart a Ba
13、rTe nder backgro und process. * Open, access, and save label formats. Use Engin e-level eve nts to mon itor prin ti ng. * Man age the BarTe nder Applicati on win dow. How To: Start and Stop an Engine An engine must be created and started in order to launch a BarTe nder process and commencqorinting.T
14、he 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 maybe left running in the background. After calli ng the Engine. Stop method, it is best practice to call the Engine. Dispose method. The Dispose m
15、ethod ensures all non-memory resources are properly released for the class; this includes shutting down the BarTe nder 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#: / Calli ng con structor
16、 with true automatically starts engine. using ( Engine btEngine = newEngine( true ) / Do something with the engine. / Stop the BarTe nder process. btE ngin e.Stop(); In VB: Calli ng con structor with true automatically starts engine. Using btEngine As NewEngine( True) Do somethi ng with the engine.
17、Stop the BarTe nder process. btE ngin e.Stop() End Usi ng 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 calli ng the Engine. Stop method. This term in ates the backgro und barte nd.exe process. Fin a
18、lly, Engine.Dispose is called automatically whe n executi on leaves the us ing stateme nt, releas ing 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 cl
19、ose all open formats without saving, but an overloaded versi on is provided that allows manual con trol. The followi ng example shows alter native code for starti ng and stopp ing an engine and sav ing cha nges: In C#: using ( Engine btEngine =new Engine() / Applicati on specific code / Explicitly s
20、tart the engine btE ngi ne.Start(); / Applicati on-specific code / Assu ming the applicati on wants to save cha nges, /it can be easily done at Stop time. btEngine.Stop( SaveOptions .SaveChanges); In VB: Using btEngine As NewEngine( True) Application specific code Explicitly start the engine btE ngi
21、 ne.Start() Applicati on-specific code Assu ming the applicati on wants to save cha nges, it can be easily done at Stop time. btE ngi ne.Stop(SaveOptio ns.SaveCha nges) End Usi ng In the above example, a newEngine is created, but not started untillater. Someapplicationactivity is assumed to execute,
22、 then the Stop method is called. In this case, cha nges to labels done while using the engine are saved back to file. The SaveOpti ons enu merati on specifies the operati on concerning ope n label formats to perform duri ng exit of BarTe nder. In the above examples and many other examples in this do
23、cume nt, 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 ensureDispose is called even if the block is exited during an exceptio n. How To: Use Engine as a Field in a Class The above examples, and mos
24、t examples in this docume nt, prese nt use of an Engine instanee in a single method. This approach is not practicalfor most real applicati ons. Start ing and stopp ing Engine objects, and by exte nsion BarTe nder processes, should be done as rarely as possible for optimal performanee. Ideally, Engin
25、e instances should be started once and only stopped at the end of the applicati on to mini mize the overhead of managing processes. The most straightforwardobject-orientedapproach is makean Engine object a field in a class and allow the encapsulating class to determ ine the Engine objects lifetime.
26、The follow ing is the mini mal 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 (an
27、d 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() /
28、 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(); / Additi
29、onal 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 f
30、irst 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 Then m_engine = NewEn
31、gine( 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
32、! 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
33、 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 resourc
34、es, 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
35、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 BarTe nd
36、er process runs BarTe nder in the 抯 user in terface. The 抯 users in terface using background without beingseen by a user. However, there may be times you will want to view and in teract with BarTe nder follow ing example shows how to view BarTe nder the Engine.Window.Visibleproperty. In C#: using (
37、Engine btEngine =new Engine() btE ngi ne.Start(); btEngine.Window.Visible =true ; / Applicati on-specific code btE ngin e.Stop(); In VB: Using btE ngine As NewE ngin e() btE ngi ne.Start() btE ngi ne.Wi ndow.Visible =True Applicati on-specific code btE ngin e.Stop() End Usi ng In the above code, a n
38、ewEngine is initialized and started. The BarTender applicati on win dow is the n show n by sett ing the Engin e.Wi ndows Visible property to true. The method assumes some in terve ning work is done. Fin ally, the engine is stopped and automatically disposed whe n leav ing the using statement. If thi
39、s code is run without any intervening work between the call to btEngine.Window.Visibleand the btEngine. Stop method, the BarTender window will only flash open for a moment, then immediately close whe n the engine is stopped and the BarTe nder process is shutdow n. The Engine Class and Print Job Eve
40、nts The Engine class provides many engin e-wide eve nts. Most of these, such as the JobQueuedor JobSent, are used to monitor the status of a print job. These sameevents are found in the LabelFormatDocument class, where they are specific to that label format. Uni ike the eve nts found in LabelFormatD
41、ocume nt, Engine eve nts provide a means to oversee print job eve nts for all label formats ope ned by the engine. For more in formatio n, refer toWorki ng with Print Job Status Eve nts Prin ti ng Label Formats A label format can be printed by calling the LabelFormatDocuments Print method. The Print
42、 method prints a job to a printers spooler and returns a Result enumeration value. It can either return immediately after spooli ng the print job or wait to return un til prin ti ng is complete. The LabelFormatDocument object contains several overloads forthe Print method to assist in label prin ti
43、ng. * Print() * Prin t(stri ng prin tJobName) * Prin t(stri ng prin tJobName, out Messages message) * Prin t(stri ng prin tJobName, int waitForCompleti on Timeout) * Prin t(stri ng prin tJobName, int waitForCompleti on Timeout, out Messages messages) Using the Print Method Several Print overloads ex
44、ist; the simplest takes no parameters. The follow ing code shows how to ope n and print a label format. In C#: LabelFormatDocume nt btFormat = btEngine.Documents.Open( c:MyLabel.btw); Result result = btFormat.Print(); In VB: Dim btFormat As LabelFormatDocume nt = btEngine.Documents.Open( c:MyLabel.b
45、tw) Dim result As Result = btFormat.Pri nt() Whenthis method is called, a Result enumeration is immediately returned. A value of Success in dicates that the print job successfully spooled to the prin ter; a value ofFailure in dicates otherwise. The Print method specifies the n ame of the print job,
46、a flag in dicat ing whether to wait for the print job to complete or not, and a collecti on of messages. The follow ing code shows how to print a format that is ope n in the BarTe nder print engine. In C#: Messagesmessages = null ; LabelFormatDocume nt btFormat = btEngine.Documents.Open( c:MyLabel.b
47、tw); Result result = btFormat.Print(PrintJob1 , out messages); In VB: Dim messages As Messages = Noth ing Dim btFormat As LabelFormatDocume nt = btEngine.Documents.Open( c:MyLabel.btw) Dim result As Result = btFormat.Pri nt(Pri ntJob1 , messages) In the above example, the application will immediatel
48、y 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 len gth before the program resumes. If the second parameter is passed as true, then the third parameter in
49、dicates the timeout len gth. Si nee the sec ond 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 aSuccess Result value. The Result variable stores the results of the print job, i ndicat
50、i ng whether the print job has succeeded or failed. Result can in dicate the print job has succeeded, timed out, or failed for a variety of reas ons. If the result indicates the print job was not successful, the messages collection contains messages indicating any errors BarTender encountered. The M
51、essages Collection While printing, one or more messages may be generated indicating print success or error. These messagescan be viewed by enumerating the Messages collection returned as a parameter from thePrint method. Each Message object in the collection contains a Text property giving a descrip
52、tion of the message. The message severity and type can be examined by using the Severity and Type properties, respectively. Printing Multiple Formats The Engine class contains a collection of LabelFormatDocument objects that are opened within the BarTender print engine. By looping through this colle
53、ction, 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 = 0 For Each format As LabelFormatD
54、ocument In btEngine.Documents i += 1 format.Print( PrintJob / Open a label format. LabelFormatDocume nt btFormat = btEngine.Documents.Open( C:MyLabel.btw); / Change the nu mber of ide ntical labels and serialized labels to print btFormat.Pri ntSetup.NumberOfSerializedLabels = 4; btFormat.Pri ntSetup
55、.Ide nticalCopiesOfLabel = 10; / Print the label Result result = btFormat.Print(); In VB: In itialize and start a new engine Using btE ngine As NewE ngin e() btE ngi ne.Start() Open a label format. Dim btFormat As LabelFormatDocume nt = btEngine.Documents.Open( C:MyLabel.btw) Change the nu mber of i
56、de ntical labels and serialized labels to print btFormat.Pri ntSetup.NumberOfSerializedLabels = 4 btFormat.Pri ntSetup.Ide nticalCopiesOfLabel = 10 Print the label Dim result As Result = btFormat.Pri nt() End Usi ng format default In the above example, a new Engine instanee is started and a label is
57、 ope ned in that Engine in sta nee. The nu mber of serialized labels and iden tical copies is cha nged, and the label is prin ted. Printing to a Different Printer Selecting a printer to print label formats can be accomplished in two differe nt ways: * Specify ing the prin ter whe n ope ning a label
58、format * Setti ng the LabelFormatDocume nt objects Prin terName property The followi ngcode dem on strates ope ning a label format using the printer, and opening a label format using a specific printer. In C#: /In itialize and start a new engine using ( Engine btEngine =new Engine() btE ngi ne.Start
59、(); / Open a label format specify ing the default prin ter LabelFormatDocument btFormat = btEngine.Documents.Open( C:MyLabel1.btw ); / Print the label Result result = btFormat.Print( PrintJob1 ); / Open a label format specifying a different printer btFormat = btEngine.Documents.Open( C:MyLabel2.btw
60、, OurPrinter_HX3000 ); / Print the label result = btFormat.Print(); In VB: Initialize and start a new engine Using btEngine As NewEngine() btEngine.Start() Open a label format specifying the default printer Dim btFormat As LabelFormatDocument = btEngine.Documents.Open( C:MyLabel1.btw ) Print the lab
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电子病历系统应用管理规范
- 医疗护理绩效考核指标体系修订
- 宠物美容接待环境安全规范
- 入户礼仪培训接待流程操作手册
- 机械设备层按节奏流水施工组织方案
- 机加车间安全生产责任制度
- 江西省南昌市2026届高三年级下学期四月检测(二模)英语试题(含答案)
- 员工健康安全检查细则制度
- 医院感染自查报告
- 冰雹灾害应急物资
- 2025年健康管理师考试题库及答案
- 4S店安全管理培训课件
- 玉米压片技术培训课件
- 聚丙烯材料安全使用说明书范本
- 依法治校制度完备档案
- GB/T 5159-2025金属粉末(不包括硬质合金用粉) 与成型和烧结有联系的尺寸变化的测定方法
- 2025年充电桩建设与运营项目可行性研究报告及总结分析
- 少突胶质瘤的护理
- (2025)预防艾梅乙母婴传播项目培训测试试题(附答案)
- 销售提成计算与管理规范
- 深圳市初中学业水平考试体育与健康科目通识考试题库
评论
0/150
提交评论