Using the Application Object

The BarTender.Application object represents the complete BarTender application. It is a top-level object in the ActiveX API, which means that all programs that are written with ActiveX Automation rely on the print functionality that is contained within the Application object.

The Application object provides basic BarTender functionality, and you can use it to control the visibility of the BarTender user interface, run a command line, save BarTender documents, and exit the bartend.exe process. It can also be used to set application-wide settings.

We recommend that you use the fully qualified names of BarTender objects, as shown in all examples in this help documentation. 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, when you use C#, you must still fully qualify references to an Application class as either BarTender.Application or System.Windows.Forms.Application.

The following example shows the minimum code that is necessary to create an instance of BarTender and exit 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

'Exit 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();

// Exit the BarTender application

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

In some cases, you want to use a BarTender application that is already running on your computer. In this scenario, you must retrieve the instance of the application that is running so that you can use it. The following example shows the minimum code that is necessary to retrieve an already running instance of BarTender and exit 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")

'Exit 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;

// Exit 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, sometimes you want to view and interact with the BarTender user interface. The following example shows how to view the user interface by using the Application.Visible property and then exit 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);

You can use other properties, methods, and objects of the Application object to do the following:

For a complete list of properties, methods, and events that are available, refer to Application Object.

Related Topics