資源簡(jiǎn)介
C#調(diào)用CodeSoft打印標(biāo)簽,使用斑馬打印機(jī),二維碼是變量。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.IO;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?LabelManager2;
using?DateTime?=?System.DateTime;
namespace?CodeSoftPrintTest
{
????public?partial?class?FrmMain?:?Form
????{
????????public?FrmMain()
????????{
????????????InitializeComponent();
????????}
????????private?IApplication?labApp?=?null;
????????private?Document?doc?=?null;
????????private?string?labFile;
????????private?void?FrmMain_Load(object?sender?EventArgs?e)
????????{
????????????foreach?(string?pkInstalledPrinters?in?System.Drawing.Printing.PrinterSettings.InstalledPrinters)
????????????{
????????????????cmbInstalledPrinters.Items.Add(pkInstalledPrinters);
????????????}
????????????if?(cmbInstalledPrinters.Items.Contains(“ZDesigner?ZT230-200dpi?ZPL“))
????????????{
????????????????cmbInstalledPrinters.Text?=?“ZDesigner?ZT230-200dpi?ZPL“;
????????????}
????????}
????????//調(diào)用CodeSoft打印首先添加引用:Lppx2.tlb(codesoft安裝后文件中)
????????private?void?btnOK_Click(object?sender?EventArgs?e)
????????{
????????????try
????????????{
????????????????labFile?=?txtLabModePath.Text;
????????????????if?(!File.Exists(labFile))
????????????????{
????????????????????MessageBox.Show(“標(biāo)簽?zāi)0宀淮嬖冢?qǐng)重新選擇!“);
????????????????}
????????????????if?(string.IsNullOrEmpty(txtBoxCode.Text))
????????????????{
????????????????????MessageBox.Show(“箱碼不能為空!“);
????????????????}
????????????????labApp?=?new?LabelManager2.Application();
????????????????labApp.Documents.Open(labFile?false);
????????????????string?filePath?=?“D:\\“?+?DateTime.Now.Year?+?DateTime.Now.Month?+?DateTime.Now.Day?+?DateTime.Now.Hour?+?DateTime.Now.Minute?+?DateTime.Now.Second?+?“.bmp“;//保存圖片的路徑??為后面預(yù)覽圖片做準(zhǔn)備
????????????????doc?=?labApp.ActiveDocument;
????????????????doc.Printer.SwitchTo(cmbInstalledPrinters.Text?“USB001“?true);//選擇打印機(jī)
????????????????doc.Variables.FreeVariables.Item(“qrcode“).Value?=?txtBoxCode.Text.ToString();//向Label檔傳入變量
????????????????doc.Variables.FreeVariables.Item(“boxcode“).Value?=?txtBoxCode.Text.ToString();//向Label檔傳入變量
????????????????string?st?=?doc.CopyImageToFile(8?“BMP“?0?100?filePath);
????????????????pictureBox1.Load(filePath);??//以圖片的形式瀏覽打印的Label
????????????????doc.PrintDocument(1);
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????MessageBox.Show(“出錯(cuò)了,原因“?+?ex.Message);
????????????}
????????????finally
????????????{
????????????????labApp.Documents.CloseAll(true);
????????????????labApp.Quit();
????????????????labApp?=?null;
????????????????doc?=?null;
????????????}
????????}
????????private?void?btnSelcetFilePath_Click(object?sender?EventArgs?e)
????????{
????????????OpenFileDialog?ofd?=?new?OpenFileDialog();?//選擇要打印的Label檔
????????????ofd.ShowDialog();
????????????txtLabModePath.Text?=?ofd.FileName;
???
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-08-28?14:38??CodeSoftPrintTest\
?????目錄???????????0??2018-08-28?14:38??CodeSoftPrintTest\.vs\
?????目錄???????????0??2018-08-28?14:38??CodeSoftPrintTest\.vs\CodeSoftPrintTest\
?????目錄???????????0??2018-08-28?14:38??CodeSoftPrintTest\.vs\CodeSoftPrintTest\v15\
?????文件???????30720??2018-08-28?15:29??CodeSoftPrintTest\.vs\CodeSoftPrintTest\v15\.suo
?????目錄???????????0??2018-08-28?14:38??CodeSoftPrintTest\.vs\CodeSoftPrintTest\v15\Server\
?????目錄???????????0??2018-08-28?14:38??CodeSoftPrintTest\.vs\CodeSoftPrintTest\v15\Server\sqlite3\
?????文件???????????0??2018-08-28?14:38??CodeSoftPrintTest\.vs\CodeSoftPrintTest\v15\Server\sqlite3\db.lock
?????文件????????4096??2018-08-28?14:38??CodeSoftPrintTest\.vs\CodeSoftPrintTest\v15\Server\sqlite3\storage.ide
?????文件???????32768??2018-08-28?14:38??CodeSoftPrintTest\.vs\CodeSoftPrintTest\v15\Server\sqlite3\storage.ide-shm
?????文件?????3114752??2018-08-28?15:27??CodeSoftPrintTest\.vs\CodeSoftPrintTest\v15\Server\sqlite3\storage.ide-wal
?????目錄???????????0??2018-08-28?15:27??CodeSoftPrintTest\CodeSoftPrintTest\
?????文件????????1150??2018-08-28?14:38??CodeSoftPrintTest\CodeSoftPrintTest.sln
?????文件?????????189??2018-08-28?14:37??CodeSoftPrintTest\CodeSoftPrintTest\App.config
?????目錄???????????0??2018-08-28?14:40??CodeSoftPrintTest\CodeSoftPrintTest\bin\
?????目錄???????????0??2018-08-28?14:56??CodeSoftPrintTest\CodeSoftPrintTest\bin\Debug\
?????文件???????16384??2018-08-28?15:24??CodeSoftPrintTest\CodeSoftPrintTest\bin\Debug\CodeSoftPrintTest.exe
?????文件?????????189??2018-08-28?14:37??CodeSoftPrintTest\CodeSoftPrintTest\bin\Debug\CodeSoftPrintTest.exe.config
?????文件???????30208??2018-08-28?15:24??CodeSoftPrintTest\CodeSoftPrintTest\bin\Debug\CodeSoftPrintTest.pdb
?????目錄???????????0??2018-08-28?14:40??CodeSoftPrintTest\CodeSoftPrintTest\bin\Release\
?????文件????????4354??2018-08-28?15:10??CodeSoftPrintTest\CodeSoftPrintTest\CodeSoftPrintTest.csproj
?????文件????????3215??2018-08-28?15:27??CodeSoftPrintTest\CodeSoftPrintTest\FrmMain.cs
?????文件????????7081??2018-08-28?15:20??CodeSoftPrintTest\CodeSoftPrintTest\FrmMain.Designer.cs
?????文件????????5817??2018-08-28?15:20??CodeSoftPrintTest\CodeSoftPrintTest\FrmMain.resx
?????目錄???????????0??2018-08-28?14:37??CodeSoftPrintTest\CodeSoftPrintTest\obj\
?????目錄???????????0??2018-08-28?15:20??CodeSoftPrintTest\CodeSoftPrintTest\obj\Debug\
?????文件??????????42??2018-08-28?15:08??CodeSoftPrintTest\CodeSoftPrintTest\obj\Debug\CodeSoftPrintTest.csproj.CoreCompileInputs.cache
?????文件????????1372??2018-08-28?15:10??CodeSoftPrintTest\CodeSoftPrintTest\obj\Debug\CodeSoftPrintTest.csproj.FileListAbsolute.txt
?????文件????????1014??2018-08-28?15:20??CodeSoftPrintTest\CodeSoftPrintTest\obj\Debug\CodeSoftPrintTest.csproj.GenerateResource.cache
?????文件?????????868??2018-08-28?15:08??CodeSoftPrintTest\CodeSoftPrintTest\obj\Debug\CodeSoftPrintTest.csproj.ResolveComReference.cache
?????文件???????11490??2018-08-28?14:38??CodeSoftPrintTest\CodeSoftPrintTest\obj\Debug\CodeSoftPrintTest.csprojAssemblyReference.cache
............此處省略19個(gè)文件信息
評(píng)論
共有 條評(píng)論