C#调用把BarTender模板.docx

上传人:b****6 文档编号:15313266 上传时间:2023-07-03 格式:DOCX 页数:21 大小:229.94KB
下载 相关 举报
C#调用把BarTender模板.docx_第1页
第1页 / 共21页
C#调用把BarTender模板.docx_第2页
第2页 / 共21页
C#调用把BarTender模板.docx_第3页
第3页 / 共21页
C#调用把BarTender模板.docx_第4页
第4页 / 共21页
C#调用把BarTender模板.docx_第5页
第5页 / 共21页
C#调用把BarTender模板.docx_第6页
第6页 / 共21页
C#调用把BarTender模板.docx_第7页
第7页 / 共21页
C#调用把BarTender模板.docx_第8页
第8页 / 共21页
C#调用把BarTender模板.docx_第9页
第9页 / 共21页
C#调用把BarTender模板.docx_第10页
第10页 / 共21页
C#调用把BarTender模板.docx_第11页
第11页 / 共21页
C#调用把BarTender模板.docx_第12页
第12页 / 共21页
C#调用把BarTender模板.docx_第13页
第13页 / 共21页
C#调用把BarTender模板.docx_第14页
第14页 / 共21页
C#调用把BarTender模板.docx_第15页
第15页 / 共21页
C#调用把BarTender模板.docx_第16页
第16页 / 共21页
C#调用把BarTender模板.docx_第17页
第17页 / 共21页
C#调用把BarTender模板.docx_第18页
第18页 / 共21页
C#调用把BarTender模板.docx_第19页
第19页 / 共21页
C#调用把BarTender模板.docx_第20页
第20页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C#调用把BarTender模板.docx

《C#调用把BarTender模板.docx》由会员分享,可在线阅读,更多相关《C#调用把BarTender模板.docx(21页珍藏版)》请在冰点文库上搜索。

C#调用把BarTender模板.docx

C#调用把BarTender模板

1、应用“Seagull.BarTender.Print“命名空间,

2、代码如下:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

//usingSystem.Threading.Tasks;

usingSystem.Windows.Forms;

usingSeagull.BarTender.Print;

//usingSeagull.BarTender;

namespaceBarTenderPrintTest1

{

   publicpartialclassForm1:

Form

   {

       publicForm1()

       {

           InitializeComponent();

       }

       //Bar

       stringdc=@"D:

\liping\BartenderPrint\BarTenderPrintTest1\BarTenderPrintTest1\bin\Debug\HW_CaiHe_and_packbox.btw";

       intff=163704004;

       stringaa="00057616-";

       inti=1;

       privatevoidbtn_print_Click(objectsender,EventArgse)

       {

           PrintLabel3();

       }

       #region第一种写法

       privatevoidPrintLabel1()

       {

          

           //创建一个BarTender打印引擎,并启用

           Engineengine=newEngine(true);

           //创建一个模板对象

           //LabelFormatDocumentformat=engine.Documents.Open("c:

\\test.btw");

           LabelFormatDocumentformat=engine.Documents.Open(@"D:

\liping\BartenderPrint\BarTenderPrintTest1\BarTenderPrintTest1\bin\Debug\HW_CaiHe_and_packbox.btw");

           format.Print("printmelabel");

           //format.Print("Selectprinter",outmessages);

           //format.Close(SaveOptions.SaveChanges );

           format.Print();

           engine.Dispose();

         

       }

       #endregion

       #region打印第二种方法

       privatevoidPrintLable2()

       {

           using(Engineengine=newEngine())

           {

               //启用一个打印引擎

               engine.Start();

               //创建一个模板对象              

               LabelFormatDocumentformat=engine.Documents.Open(@"D:

\liping\BartenderPrint\BarTenderPrintTest1\BarTenderPrintTest1\bin\Debug\HW_CaiHe_and_packbox.btw");

              //打印

               //format.Print("printmelabel");

               //改变标签打印数份连载

               format.PrintSetup.NumberOfSerializedLabels=1;

               //设定印标签打印数量

               format.PrintSetup.IdenticalCopiesOfLabel=1;

               ResultnResult=format.Print();

               //指定打印机打印,不指定则使用默认打印机

               format.PrintSetup.PrinterName="BarCodePrinterT-4503E";

               //Displaytheprintresult.

               //Console.WriteLine("Printstatus="+nResult);

               MessageBox.Show("打印提示:

"+nResult);

               //Closethecurrentformatwithoutsaving.

               //SaveOptions有三个值DoNotSaveChanges:

不保存,PromptSave:

提示是否保存  SaveChanges:

保存

               format.Close(SaveOptions.DoNotSaveChanges);               

               //结束打印引擎

               engine.Stop();

           }

       }

       #endregion

       #region第三种打印方法改变标签的值

       privatevoidPrintLabel3()

       {

           using(Engineengine=newEngine(true))

           {

               LabelFormatDocumentbtFormat=engine.Documents.Open(dc);

               //MessageBox.Show(btFormat.SubStrings[0].Name);

               ////获取标签的值

               //stringAddressSubstring=btFormat.SubStrings["HWbarcode1"].Value;

               //MessageBox.Show(AddressSubstring);

               //修改标签的值

               //btFormat.SubStrings["Address"].Value="1313MockingbirdLane,Anywhere,USA";

               //btFormat.SubStrings["Name"].Value="JohnDoe";

               //btFormat.SubStrings["Quantity"].Value="10";

               intdd=ff+i;

               i++;

               btFormat.SubStrings["HWbarcode1"].Value=aa+dd.ToString();

              //改变标签打印数份连载

               btFormat.PrintSetup.NumberOfSerializedLabels=1;

               //设定印标签打印数量

               btFormat.PrintSetup.IdenticalCopiesOfLabel=1;

               ResultnResult=btFormat.Print();

               //指定打印机打印,不指定则使用默认打印机

               btFormat.PrintSetup.PrinterName="BarCodePrinterT-4503E";

               MessageBox.Show("打印提示:

"+nResult);

               btFormat.Close(SaveOptions.DoNotSaveChanges);

               //结束打印引擎

               engine.Stop();

           }

       }

       #endregion

   }

}

 

三、bartender说明文档部分

CreatingaBarTenderPrintEngine

TheEngineclassrepresentsaBarTenderprocessandprovidesthebackboneforprogrammingwiththeBarTenderPrintSDK.AllprogramswrittenwiththeBarTenderPrintSDKwillrelyontheEngineclasstoprovideBarTenderprintfunctionality.

TheBarTenderPrintEngine

TheBarTenderprocess(bartend.exe)providesstandardBarTenderfunctionality,suchasopeninglabelformats,changinglabelsettings,andprinting.TheBarTenderbackgroundprocessiscontrolledusinganinstanceoftheEngineclass.

TheRoleoftheEngineClass

TheEngineclasscontainsmanymethods,properties,andeventstoassistinprintingandcontrollingtheBarTenderPrintEngine.

FeaturesoftheEngineClass

TheEngineclassallowsusersto:

∙Start,stop,andrestartaBarTenderbackgroundprocess.

∙Open,access,andsavelabelformats.

∙UseEngine-leveleventstomonitorprinting.

∙ManagetheBarTenderApplicationwindow.

HowTo:

StartandStopanEngine

AnenginemustbecreatedandstartedinordertolaunchaBarTenderprocessandcommenceprinting.TheEngineclassprovidestheEngine.StopmethodtoexplicitlyshutdowntheBarTenderPrintEngine.Iftheengineisnotstopped,abartend.exeprocessmaybeleftrunninginthebackground.AftercallingtheEngine.Stopmethod,itisbestpracticetocalltheEngine.Disposemethod.TheDisposemethodensuresallnon-memoryresourcesareproperlyreleasedfortheclass;thisincludesshuttingdowntheBarTenderprocessifEngine.Stopwasnotsuccessfullycalled.

Thefollowingistheminimalcodenecessarytocreate,start,stop,anddisposeanEngineobject:

InC#:

//Callingconstructorwith'true'automaticallystartsengine.

using(EnginebtEngine=newEngine(true))

{

//Dosomethingwiththeengine.

//StoptheBarTenderprocess.

btEngine.Stop();

}

InVB:

'Callingconstructorwith'true'automaticallystartsengine.

UsingbtEngineAsNewEngine(True)

'Dosomethingwiththeengine.

'StoptheBarTenderprocess.

btEngine.Stop()

EndUsing

Intheaboveexample,anengineiscreatedandstartedimplicitlybypassing'true'asanargumenttotheconstructor.TheengineisthenstoppedbycallingtheEngine.Stopmethod.Thisterminatesthebackgroundbartend.exeprocess.Finally,Engine.Disposeiscalledautomaticallywhenexecutionleavesthe'using'statement,releasingallEngineresources.

ItisalsopossibletostarttheengineexplicitlyafterithasbeencreatedusingthedefaultEngineconstructorandtheEngine.Startmethod.Bydefault,Engine.Stopwillcloseallopenformatswithoutsaving,butanoverloadedversionisprovidedthatallowsmanualcontrol.

Thefollowingexampleshowsalternativecodeforstartingandstoppinganengineandsavingchanges:

InC#:

using(EnginebtEngine=newEngine())

{

//Applicationspecificcode

//Explicitlystarttheengine

btEngine.Start();

//Application-specificcode

//Assumingtheapplicationwantstosavechanges,

//itcanbeeasilydoneatStoptime.

btEngine.Stop(SaveOptions.SaveChanges);

}

InVB:

UsingbtEngineAsNewEngine(True)

'Applicationspecificcode

'Explicitlystarttheengine

btEngine.Start()

'Application-specificcode

'Assumingtheapplicationwantstosavechanges,

'itcanbeeasilydoneatStoptime.

btEngine.Stop(SaveOptions.SaveChanges)

EndUsing

Intheaboveexample,anewEngineiscreated,butnotstarteduntillater.Someapplicationactivityisassumedtoexecute,thentheStopmethodiscalled.Inthiscase,changestolabelsdonewhileusingtheenginearesavedbacktofile.TheSaveOptionsenumerationspecifiestheoperationconcerningopenlabelformatstoperformduringexitofBarTender.

Intheaboveexamplesandmanyotherexamplesinthisdocument,theEngine.Disposemethodiscalledimplicitlybya'using'statement.Whileitisnotalwaysappropriatetoutilize'using',itisaconvenientwaytoensureDisposeiscalledeveniftheblockisexitedduringanexception.

HowTo:

UseEngineasaFieldinaClass

Theaboveexamples,andmostexamplesinthisdocument,presentuseofanEngineinstanceinasinglemethod.Thisapproachisnotpracticalformostrealapplications.StartingandstoppingEngineobjects,andbyextensionBarTenderprocesses,shouldbedoneasrarelyaspossibleforoptimalperformance.Ideally,Engineinstancesshouldbestartedonceandonlystoppedattheendoftheapplicationtominimizetheoverheadofmanagingprocesses.Themoststraightforwardobject-orientedapproachismakeanEngineobjectafieldinaclassandallowtheencapsulatingclasstodeterminetheEngineobject'slifetime.

ThefollowingistheminimalsuggestedcodeformakinganEngineobjectafieldinaclass:

InC#:

publicclassEngineWrapper:

IDisposable

{

//EngineField

privateEnginem_engine=null;

//Thispropertywillcreateandstarttheenginethefirsttimeitis

//called.Mostmethodsinthisclass(andmethodsinchildclasses)

//shouldutilizethispropertyinsteadofthem_enginefield.

protectedEngineBtEngine

{

get

{

//Iftheenginehasnotbeencreatedyet,createandstartit.

if(m_engine==null)

{

m_engine=newEngine(true);

}

returnm_engine;

}

}

//ImplementIDisposable

publicvoidDispose()

{

//Theengineonlyneedstobestoppedanddisposedifitwas

//created.Usethefieldhere,nottheproperty.Otherwise,

//youmightcreateanewinstanceintheDisposemethod!

if(m_engine!

=null)

{

//St

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2