Simple Bartender .net Application With Visual Studio 2013 Follow

Ian Cummings

Follow the below steps in order to create a simple Windows form application that integrates with BarTender.


1.  From within Visual Studio select the "File>New Project" menu item.  Select the "Visual C#>Windows Desktop" template type, and then choose the ,"Windows Forms Application" item.  Specify a unique name and location for the project and click OK.




2.  In the "Solution Explorer" for the project double click on the solution's "Properties" to configure the solution's settings.




Choose the target framework you wish to work with for your solution.  The default, ".NET Framework 4.5" is acceptable, but you make select frameworks 4.5.1 or 3.5 if you prefer.




As BarTender is currently only available as a 32 bit (x86) application you'll need to specify this under the "Build" section on the solution properties.  Failure to set this appropriately will cause an error on an x64 computer system.




If you selected the .NET Frameworks 4.5 or 4.5.1 in the solution properties you'll need to make a small alteration to the app configuration.  To do this, double click the "App.config" file from the Solution Explorer and add the, "useLegacyV2RuntimeActivationPolicy" attribute to the <startup> tag giving it a value of "true".  See below an example of this:

<?xml version="1.0" encoding="utf-8" ?>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />


In order for your application to integrate with BarTender a reference should be added to the project for the BarTender .NET component, which is listed as "Seagull.BarTender.Print" in the "Assemblies>Extensions" list.  Tck the checkbox alongside it and click OK.




In the form designer view add a command button to the form and then double click it to edit the underlying code.




To start, add a using reference to the "Seagull.BarTender.Print" component at the beginning of the code alongside other using statements, thus bringing the BarTender class into scope.


using Seagull.BarTender.Print;


Enter in your BarTender specific automation code into the contents of the button's click event.  In the below example we create a BarTender engine instance, start it, define an application window making it visible, pause for five seconds, and then lastly, stopping the BarTender engine instance.

private void button1_Click(object sender, EventArgs e)
       // Create and Start the BarTender print engine.
       Engine btEngine = new Engine();
       // Set the BarTender main window dimensions.
       btEngine.Window.Width = 800;
       btEngine.Window.Height = 600;
       // Set the window location.
       btEngine.Window.Top = 100;
       btEngine.Window.Left = 100;
       // Make BarTender visible to the user.
       btEngine.Window.Visible = true;
       // Wait five seconds so the user can see the window.
       // Stop the BarTender print engine.


Save all your work and test run the project by clicking the "Start" button in the toolbar of Visual Studio.




Legacy Poster
Comment actions Permalink

Hi Ian, this didn't work for me when running as 32bit app.  I had to change it to a 64bit app - noticed that the dll was taken from "Program Files" folder not "Program Files x86"

Ian Cummings
Comment actions Permalink

Dwayne: The above instructions were for older BarTender releases (v10.1 or before), and thus does not apply to BarTender 2016 where much of these details changed due to the introduction of an x64 application and our targeting of the v4.0 .NET framework.

Don Hopkins
Comment actions Permalink

Hi, Ian, I got this to work, do you have an example of it bringing up a label and printing it.Thanks Don

Don Hopkins
Comment actions Permalink

I am using a old version --- so this worked fine.

Please sign in to leave a comment.