![C調(diào)用把BarTender模板_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/2/195d47a9-4368-46a6-8db8-57ed6b173156/195d47a9-4368-46a6-8db8-57ed6b1731561.gif)
![C調(diào)用把BarTender模板_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/2/195d47a9-4368-46a6-8db8-57ed6b173156/195d47a9-4368-46a6-8db8-57ed6b1731562.gif)
![C調(diào)用把BarTender模板_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/2/195d47a9-4368-46a6-8db8-57ed6b173156/195d47a9-4368-46a6-8db8-57ed6b1731563.gif)
![C調(diào)用把BarTender模板_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/2/195d47a9-4368-46a6-8db8-57ed6b173156/195d47a9-4368-46a6-8db8-57ed6b1731564.gif)
![C調(diào)用把BarTender模板_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/2/195d47a9-4368-46a6-8db8-57ed6b173156/195d47a9-4368-46a6-8db8-57ed6b1731565.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、1、應(yīng)用“ 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; /創(chuàng)建一個BarTender打印引擎 ,并啟用 Engine engine = new Engine(true); /創(chuàng)建一個模板對象
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(); /創(chuàng)建一個模板對象
13、 LabelFormatDocument format = engine.Documents.Open("D:lipingBartenderPrintBarTenderPrintTest1BarTenderPrintTest1binDebugHW_CaiHe_and_packbox.btw"); /打印
14、 /format.Print("print me label"); /改變標簽打印數(shù)份連載
15、; format.PrintSetup.NumberOfSerializedLabels =1; /設(shè)定印標簽打印數(shù)量 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); /結(jié)束打印引擎
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 (); /改變標簽打印數(shù)份連載 btFormat.PrintSetup.NumberOfSerializedLabels
29、 = 1; /設(shè)定印標簽打印數(shù)量 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); /結(jié)束打印引擎 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年五年級班級管理工作總結(jié)(3篇)
- 2025年代理權(quán)轉(zhuǎn)讓協(xié)議范文(2篇)
- 2025年五年級下學期語文教師工作總結(jié)模版(三篇)
- 2025年鄉(xiāng)村中學教師七年級語文教學工作總結(jié)(3篇)
- 2025年個人擔保貸款合同參考樣本(2篇)
- 互聯(lián)網(wǎng)企業(yè)調(diào)研居間合同
- 教育實驗室裝修項目協(xié)議
- 疫情封閉小區(qū)大門施工方案
- 健身房裝修合同范本版
- 咖啡館裝飾設(shè)計合同
- 《數(shù)學課程標準》義務(wù)教育2022年修訂版(原版)
- 各種標本采集的技術(shù)-痰標本的采集(護理技術(shù))
- 2024年湖南中考道德與法治試卷真題答案解析(精校打?。?/a>
- 實驗室的設(shè)計規(guī)劃
- 注冊安全工程師《安全生產(chǎn)管理知識》科目知識要點
- 《新時代公民道德建設(shè)實施綱要》、《新時代愛國主義教育實施綱要》知識競賽試題庫55題(含答案)
- 2024-2030年中國假睫毛行業(yè)市場發(fā)展趨勢與前景展望戰(zhàn)略分析報告
- 2019-2020學年七年級(上)期末數(shù)學試卷2附解析
- 電話接聽技巧與服務(wù)質(zhì)量提升方案三篇
- 德國職業(yè)學校教育質(zhì)量保障體系研究
- 2023-2024學年北師大版數(shù)學八年級上冊 期末測試卷
評論
0/150
提交評論