Using the Application Object

The BarTender.Application object represents the complete BarTender application. It is a top level object in the ActiveX API, meaning that all programs written with the ActiveX Automation rely on the print functionality contained within the Application object. The Application object provides basic BarTender functionality, and allows you to control the visibility of the BarTender user interface, execute a command line, save BarTender documents, and quit the bartend.exe process. It can be used to set application wide settings.

We recommend that you use the fully qualified names of BarTender objects, as we do in all examples in this help. If you prefer to use the shorter form of the names, you can add a VB.NET Imports BarTender or a C# using BarTender command to your program. However, with C#, you will still need to fully qualify references to an Application class as either BarTender.Application or System.Windows.Forms.Application

The following is the minimal code necessary to create an instance of BarTender and quit the BarTender process:

ClosedIn VB.NET

'Declare a BarTender application variable

Dim btApp As BarTender.Application

'Create a new instance of BarTender

btApp = New BarTender.Application

'Quit the BarTender application

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)

ClosedIn C#

// Declare a BarTender application variable

BarTender.Application btApp;

// Create a new instance of BarTender

btApp = new BarTender.Application();

// Quit the BarTender application

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

In some cases, you may find that you want to use a BarTender application that is already running on your computer. Here, you will need to retrieve (or get) the instance of the application that is running in order to use it. The following is the minimal code necessary to retrieve an already running instance of BarTender and quit the BarTender process:

ClosedIn VB.NET

'Declare a BarTender application variable

Dim btApp As BarTender.Application

'Retrieve an existing instance of BarTender

btApp = GetObject(, "BarTender.Application")

'Quit the BarTender application

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)

ClosedIn C#

// Retrieve an existing instance of BarTender

// Store this instance as an object variable in C#

object btObject = System.Runtime.InteropServices.Marshal.GetActiveObject("BarTender.Application");

// Convert the object variable to a BarTender application variable

BarTender.Application btApp = btObject as BarTender.Application;

// Quit the BarTender application

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

By default, the Application object runs a BarTender process in the background without being seen by a user. However, there may be times you will want to view and interact with BarTender’s user interface. The following example shows how to view BarTender’s user interface using the Application.Visible property, then quit the application.

ClosedIn VB.NET

'Declare a BarTender application variable

Dim btApp As BarTender.Application

'Create a new instance of BarTender variable

btApp = New BarTender.Application

'Set the BarTender application visible

btApp.Visible = True

'End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)

ClosedIn C#

// Declare a BarTender application variable

BarTender.Application btApp;

// Create a new instance of BarTender

btApp = new BarTender.Application();

// Set the BarTender application visible

btApp.Visible = true;

// End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

Other properties, methods, and objects of the Application object allow you to:

For a complete list of properties, methods, and events available, see documentation on the Application object.

Related Topics