1. 程式人生 > >Bartender條碼使用方法C#

Bartender條碼使用方法C#

安裝在C盤較好吧C:\ProgramFiles (x86)\Seagull\BarTender Suite

這個破解補丁是希望安裝在C盤的吧,哈哈。

破解後紅框處不會出現“演示”二字,因為演示版在程式裡不能列印


VS2005引用Seagull.BarTender.Print.dll,這個DLL檔案在

C:\Program Files (x86)\Seagull\BarTenderSuite\SDK\Assemblies資料夾裡


開始做個DEMO列印吧,VS2010程式碼如下

using System;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

usingSeagull.BarTender.Print;//這裡不能少

using System.Diagnostics;

namespace test

{

    public partialclassForm1 :Form

    {

       public Form1()

       {

           InitializeComponent();

       }

private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                Engine btEngine = new Engine();
                btEngine.Start();
                string lj = AppDomain.CurrentDomain.BaseDirectory + "mb\\test.btw";
                LabelFormatDocument btFormat = btEngine.Documents.Open(lj);
                //LabelFormatDocument btFormat = btEngine.Documents.Open(Path.Combine("D://Barcode//MR//MR//bin//Debug//mb", "test2" + ".btw"));
                


                //對模版相應欄位進行賦值
                btFormat.SubStrings["tm"].Value = txt_barcode.Text;
                btFormat.SubStrings["model"].Value = txt_part.Text;


                //指定印表機名
                btFormat.PrintSetup.PrinterName = "IT_Label";
                //改變標籤列印數份連載
                btFormat.PrintSetup.NumberOfSerializedLabels = 1;
                //列印份數                  
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;


                //Result nResult = format.Print();
                //btFormat.Print();


                Messages messages;
                int waitout = 10000; // 10秒 超時
                Result nResult1 = btFormat.Print("標籤列印軟體", waitout, out messages);


                btFormat.PrintSetup.Cache.FlushInterval = CacheFlushInterval.PerSession;
                //不儲存對開啟模板的修改
                //btFormat.Close(SaveOptions.DoNotSaveChanges);
                //結束列印引擎                 
                btEngine.Stop();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception: " + ex.Message);
                return;
            }

        }

BarTender的各種錯誤和解決方法

1:
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
在app.config檔案裡設定
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>


2:
Could not load file or assembly 'Seagull.BarTender.Print, Version=10.1.4.1, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7' or one of its dependencies. An attempt was made to load a program with an incorrect format.
其他資訊: 未能載入檔案或程式集“Seagull.BarTender.Print, Version=10.1.4.1, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7”或它的某一個依賴項
於是在專案->屬性->生成,將目標平臺改成x86,編譯即能通過。