Simple Bartender .net Application With Visual Studio 2013 追蹤

0
Avatar
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.

 

blob1429691742468.png?1429691748

 

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

 

blob1429692043427.png?1429692048

 

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.

 

blob1429692172349.png?1429692178

 

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.

 

blob1429692205178.png?1429692210

 

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" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

 

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.

 

blob1429692370732.png?1429692376

 

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

 

blob1429692472460.png?1429692478

 

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();
       btEngine.Start();
 
       // 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.
       System.Threading.Thread.Sleep(5000);
 
       // Stop the BarTender print engine.
       btEngine.Stop();
}

 

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

 

Enjoy!

4 意見

0
Avatar
Legacy Poster
評論操作 永久連結

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"

0
Avatar
Ian Cummings
版主
評論操作 永久連結

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.

0
Avatar
Don Hopkins
評論操作 永久連結

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

0
Avatar
Don Hopkins
評論操作 永久連結

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

登入寫評論。