}
returnm_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 ClassEngineWrapper ImplementsIDisposable ' Engine Field
Privatem_engineAs 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 PropertyBtEngine() As Engine Get
' If the engine has not been created yet, create and start it. Ifm_engineIs Nothing Then m_engine = NewEngine(True) End If
Returnm_engine End Get End Property
' ImplementIDisposable
Public SubDispose() ImplementsIDisposable.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! Ifm_engineIsNot 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 Interface
By 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 how to view BarTender抯 users interface using the Engine.Window.Visible property. In C#:
using (EnginebtEngine = newEngine()) {
btEngine.Start();
btEngine.Window.Visible = true; // Application-specific code btEngine.Stop(); } In VB:
UsingbtEngineAs NewEngine() 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.Window'sVisible 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 Events
The 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 Formats
A label format can be printed by calling the LabelFormatDocument'sPrint 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 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)
相关推荐: