入侵织梦网站,山东城乡建设厅网站,做怎么网站收费,公司做企业网站须知效果 学习路径
C# winform调用Bartender进行自定义打印、批量打印、检索文件夹中的模板_哔哩哔哩_bilibili
一、初始环境搭建见#xff1a;
c#:winform引入bartender-CSDN博客https://blog.csdn.net/weixin_46001736/article/details/143989473?sharetypeblogdetails…效果 学习路径
C# winform调用Bartender进行自定义打印、批量打印、检索文件夹中的模板_哔哩哔哩_bilibili
一、初始环境搭建见
c#:winform引入bartender-CSDN博客https://blog.csdn.net/weixin_46001736/article/details/143989473?sharetypeblogdetailsharerId143989473sharereferPCsharesourceweixin_46001736spm1011.2480.3001.8118
二、创建bartender文件
1、创建两个文件test.btw,test2.btw效果图 2、创建流程
文本-单行 ①建立文本姓名普通文本
直接输入标题便可 ②建立文本:李四 点击名称输入数据源 输入数据 其余建立文本方式与这个一致目的是便于vs可操控bartender数据
③建立二维码内容
选择样式之后左击鼠标展示到页面 双击二维码进行属性编辑
可见性设置为“无”为了隐藏二维码下的文本 右击数据源-删除原有数据源123456
右击数据源-新建 选择已有或新建数据源 按照上述信息将姓名、性别、班级添加入二维码 3、将两个btw存入项目文件夹中 三、编写vs文件
1、修改App.config,避免不兼容问题 2、Form1.cs
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 Seagull.BarTender.Print;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;namespace test_bartender
{//这里的Form1继承自Formpublic partial class Form1 : Form{public Form1(){//来自分布类的方法-窗口展示InitializeComponent();}public Engine engine new Engine();//定义一个打印机引擎public LabelFormatDocument format null;//获取模板内容public static string path Application.StartupPath \Model;//模板路径(Application.StartupPath获取当前执行路径public static DirectoryInfo direct new DirectoryInfo(path);//实例化指定文件路径的目录public FileInfo[] fileInfo direct.GetFiles();//获取指定路径上的所有文件public ListString fileList new Liststring();//所有模板文件数据定义一个空列表//加载模板文件名称至listBox控件public void loadList_Model() { //循环文件列表foreach(var item in fileInfo){//筛选出指定格式的文件如果文件后缀为.BTW)if (item.Extension.ToUpper() .BTW){fileList.Add(item.Name);//将文件的Name存入列表fileList}}//数据绑定这里绑定了数据源到fileList之后就不能在对这个进行绑定否则造成重复所以后面模糊查询需要创建新的数据源listb_models.DataSource fileList;}//执行打印//printmodel:模板名//printnum:数量//Sname:姓名//Sex:性别//Sclass:班级public void Pint_model(string printmodel, int printnum, string Sname, string Sex, string Sclass){for (int i 0; i printnum; i){engine.Start();//开始打印btn_print.Enabled false;//防止按钮重复点击开始打印九设置打印为进制format engine.Documents.Open(path $\\{printmodel});//从路径path中的模板printmodel去打开文件if (Sname ! ){format.SubStrings[姓名].Value tb_name.Text;format.SubStrings[性别].Value tb_sex.Text;format.SubStrings[班级].Value tb_class.Text;}Result rel format.Print();//获取打印状态if (rel Result.Success){MessageBox.Show(打印成功);}else{MessageBox.Show(打印失败);}btn_print.Enabled true;//启加载完成启用按钮engine.Stop();//打印完成}}//窗口加载时使用private void Form1_Load(object sender, EventArgs e){loadList_Model();//启用加载模板}private void tb_model_TextChanged(object sender, EventArgs e){string searchTxt tb_model.Text;//获取文本框输入的要查询的数据Liststring searchModel new Liststring();//声明一个列表存放 查询出的文件名if (tb_model.Text.Trim().Length 0)//如果查询框中的数据为空{//创建新的数据源:BindingSourceBindingSource bs new BindingSource();bs.DataSource fileList;//将查询的全部模板数据存入这个新的数据源listb_models.DataSource bs;//将重新查到的全部模板数据又重新绑定给listb_models}else//有输入的数值即需要模糊查询{for (int i 0; i fileList.Count; i)//对全部模板数据进行循环{//查询我的全部模板数据的单项查询这一项的是否包含searchTxt输入的值searchModel fileList.Where(m m.Contains(searchTxt)).ToList();//查询是否子项是否包含输入的值}BindingSource bs new BindingSource();//新建数据源bs.DataSource searchModel;//数据源 绑定含有输入的数据的项listb_models.DataSource bs;//ListBox控件重新绑定数据} }private void label4_Click(object sender, EventArgs e){}private void textBox5_TextChanged(object sender, EventArgs e){}private void textBox2_TextChanged(object sender, EventArgs e){}private void numericUpDown1_ValueChanged(object sender, EventArgs e){}//按钮点击事件private void btn_print_Click(object sender, EventArgs e){int num (int) nup_num .Value;//获取打印数量string modelname;if (listb_models.SelectedIndex0) {modelname listb_models.SelectedItem.ToString();//获取ListBox选中的模板Pint_model(modelname,num,tb_name.Text,tb_sex.Text,tb_class.Text);}else{MessageBox.Show(请选择模板);}}}继承举个例子现在有个Human类//public partial class Human//{// public string Name { get; set; }// public int Age { get; set; }//}现在有学生类Studentpublic partial class Student{//学生类也存在Name和Age属性public string Name { get; set; }public int Age { get; set; }//还有自己独有的一些属性public int score { get; set; }//由于Name和Age可以直接来自Hum就可以替换成 public partial class Student:Human如下}//public partial class Student :Human//{// //还有自己独有的一些属性// public int score { get; set; }// //通过继承Student除了自己独有的属性score还含有Huam的全部属性//}}3、Form1.cs设计页面 4、Form1.Designer.cs namespace test_bartender
{//分部类相同的命名空间下会将相同的类合并在Form1.cs可以看到也有一个类Form1,运行的时候这里的类会合并到Form1.cs文件中partial class Form1{/// summary/// 必需的设计器变量。/// /summaryprivate System.ComponentModel.IContainer components null;/// summary/// 清理所有正在使用的资源。/// /summary/// param namedisposing如果应释放托管资源为 true否则为 false。/paramprotected override void Dispose(bool disposing){if (disposing (components ! null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// summary/// 设计器支持所需的方法 - 不要修改/// 使用代码编辑器修改此方法的内容。/// /summaryprivate void InitializeComponent(){this.listb_models new System.Windows.Forms.ListBox();this.label1 new System.Windows.Forms.Label();this.label2 new System.Windows.Forms.Label();this.tb_model new System.Windows.Forms.TextBox();this.label3 new System.Windows.Forms.Label();this.tb_name new System.Windows.Forms.TextBox();this.tb_class new System.Windows.Forms.TextBox();this.label4 new System.Windows.Forms.Label();this.tb_sex new System.Windows.Forms.TextBox();this.label5 new System.Windows.Forms.Label();this.label6 new System.Windows.Forms.Label();this.backgroundWorker1 new System.ComponentModel.BackgroundWorker();this.nup_num new System.Windows.Forms.NumericUpDown();this.btn_print new System.Windows.Forms.Button();((System.ComponentModel.ISupportInitialize)(this.nup_num)).BeginInit();this.SuspendLayout();// // listb_models模板内容// this.listb_models.Cursor System.Windows.Forms.Cursors.Hand;this.listb_models.FormattingEnabled true;this.listb_models.ItemHeight 15;this.listb_models.Location new System.Drawing.Point(21, 111);this.listb_models.Name listb_models;this.listb_models.Size new System.Drawing.Size(280, 244);this.listb_models.TabIndex 3;// // label1-大标题// this.label1.AutoSize true;this.label1.Font new System.Drawing.Font(宋体, 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label1.ForeColor System.Drawing.SystemColors.ControlText;this.label1.Location new System.Drawing.Point(183, 22);this.label1.Name label1;this.label1.Size new System.Drawing.Size(269, 20);this.label1.TabIndex 0;this.label1.Text Winform调用Bartender打印;// // label2-模板名标题// this.label2.AutoSize true;this.label2.Font new System.Drawing.Font(宋体, 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label2.Location new System.Drawing.Point(18, 80);this.label2.Name label2;this.label2.Size new System.Drawing.Size(71, 15);this.label2.TabIndex 1;this.label2.Text 模板名;// // tb_model输入的模板名// this.tb_model.Location new System.Drawing.Point(84, 77);this.tb_model.Name tb_model;this.tb_model.Size new System.Drawing.Size(217, 25);this.tb_model.TabIndex 2;this.tb_model.TextChanged new System.EventHandler(this.tb_model_TextChanged);// // label3-姓名标题// this.label3.AutoSize true;this.label3.Font new System.Drawing.Font(宋体, 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label3.Location new System.Drawing.Point(372, 111);this.label3.Name label3;this.label3.Size new System.Drawing.Size(55, 15);this.label3.TabIndex 4;this.label3.Text 姓名;// // tb_name-姓名文本框// this.tb_name.BorderStyle System.Windows.Forms.BorderStyle.None;this.tb_name.Location new System.Drawing.Point(420, 108);this.tb_name.Name tb_name;this.tb_name.Size new System.Drawing.Size(100, 18);this.tb_name.TabIndex 5;this.tb_name.TextChanged new System.EventHandler(this.textBox2_TextChanged);// // tb_class-班级文本框// this.tb_class.BorderStyle System.Windows.Forms.BorderStyle.None;this.tb_class.Location new System.Drawing.Point(420, 148);this.tb_class.Name tb_class;this.tb_class.Size new System.Drawing.Size(100, 18);this.tb_class.TabIndex 7;// // label4-班级标题// this.label4.AutoSize true;this.label4.Font new System.Drawing.Font(宋体, 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label4.Location new System.Drawing.Point(372, 151);this.label4.Name label4;this.label4.Size new System.Drawing.Size(55, 15);this.label4.TabIndex 6;this.label4.Text 班级;this.label4.Click new System.EventHandler(this.label4_Click);// // tb_sex-性别标题// this.tb_sex.BorderStyle System.Windows.Forms.BorderStyle.None;this.tb_sex.Location new System.Drawing.Point(420, 188);this.tb_sex.Name tb_sex;this.tb_sex.Size new System.Drawing.Size(100, 18);this.tb_sex.TabIndex 9;// // label5-性别标题// this.label5.AutoSize true;this.label5.Font new System.Drawing.Font(宋体, 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label5.Location new System.Drawing.Point(372, 191);this.label5.Name label5;this.label5.Size new System.Drawing.Size(55, 15);this.label5.TabIndex 8;this.label5.Text 性别;// // label6-数量标题// this.label6.AutoSize true;this.label6.Font new System.Drawing.Font(宋体, 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.label6.Location new System.Drawing.Point(372, 260);this.label6.Name label6;this.label6.Size new System.Drawing.Size(55, 15);this.label6.TabIndex 10;this.label6.Text 数量;// // nup_num-数量文本框// this.nup_num.Location new System.Drawing.Point(420, 250);this.nup_num.Name nup_num;this.nup_num.Size new System.Drawing.Size(100, 25);this.nup_num.TabIndex 11;this.nup_num.ValueChanged new System.EventHandler(this.numericUpDown1_ValueChanged);// // btn_print-打印按钮// this.btn_print.BackColor System.Drawing.SystemColors.ActiveCaption;this.btn_print.Font new System.Drawing.Font(宋体, 10F);this.btn_print.ForeColor System.Drawing.SystemColors.ButtonHighlight;this.btn_print.ImageAlign System.Drawing.ContentAlignment.MiddleRight;this.btn_print.Location new System.Drawing.Point(375, 316);this.btn_print.Name btn_print;this.btn_print.Size new System.Drawing.Size(150, 30);this.btn_print.TabIndex 12;this.btn_print.Text 打印;this.btn_print.UseVisualStyleBackColor false;this.btn_print.Click new System.EventHandler(this.btn_print_Click);// // Form1-窗口// this.AutoScaleDimensions new System.Drawing.SizeF(8F, 15F);this.AutoScaleMode System.Windows.Forms.AutoScaleMode.Font;this.ClientSize new System.Drawing.Size(635, 387);this.Controls.Add(this.btn_print);this.Controls.Add(this.nup_num);this.Controls.Add(this.label6);this.Controls.Add(this.tb_sex);this.Controls.Add(this.label5);this.Controls.Add(this.tb_class);this.Controls.Add(this.label4);this.Controls.Add(this.tb_name);this.Controls.Add(this.label3);this.Controls.Add(this.listb_models);this.Controls.Add(this.tb_model);this.Controls.Add(this.label2);this.Controls.Add(this.label1);this.Name Form1;this.Text 窗口;this.Load new System.EventHandler(this.Form1_Load);((System.ComponentModel.ISupportInitialize)(this.nup_num)).EndInit();this.ResumeLayout(false);this.PerformLayout();}#endregionprivate System.Windows.Forms.Label label1;private System.Windows.Forms.Label label2;private System.Windows.Forms.TextBox tb_model;private System.Windows.Forms.Label label3;private System.Windows.Forms.TextBox tb_name;private System.Windows.Forms.TextBox tb_class;private System.Windows.Forms.Label label4;private System.Windows.Forms.TextBox tb_sex;private System.Windows.Forms.Label label5;private System.Windows.Forms.Label label6;private System.Windows.Forms.ListBox listb_models; private System.ComponentModel.BackgroundWorker backgroundWorker1;private System.Windows.Forms.NumericUpDown nup_num;private System.Windows.Forms.Button btn_print;}
}
四、运行 文章转载自: http://www.morning.lfgql.cn.gov.cn.lfgql.cn http://www.morning.rtmqy.cn.gov.cn.rtmqy.cn http://www.morning.xqkcs.cn.gov.cn.xqkcs.cn http://www.morning.htrzp.cn.gov.cn.htrzp.cn http://www.morning.sfsjh.cn.gov.cn.sfsjh.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.ktmbp.cn.gov.cn.ktmbp.cn http://www.morning.qjlkp.cn.gov.cn.qjlkp.cn http://www.morning.bjjrtcsl.com.gov.cn.bjjrtcsl.com http://www.morning.zqxhn.cn.gov.cn.zqxhn.cn http://www.morning.mwbqk.cn.gov.cn.mwbqk.cn http://www.morning.cfmrb.cn.gov.cn.cfmrb.cn http://www.morning.yrhpg.cn.gov.cn.yrhpg.cn http://www.morning.nnpwg.cn.gov.cn.nnpwg.cn http://www.morning.rytps.cn.gov.cn.rytps.cn http://www.morning.tdhxp.cn.gov.cn.tdhxp.cn http://www.morning.ywpcs.cn.gov.cn.ywpcs.cn http://www.morning.hxxwq.cn.gov.cn.hxxwq.cn http://www.morning.nktgj.cn.gov.cn.nktgj.cn http://www.morning.cmdfh.cn.gov.cn.cmdfh.cn http://www.morning.mlckd.cn.gov.cn.mlckd.cn http://www.morning.drndl.cn.gov.cn.drndl.cn http://www.morning.zqcsj.cn.gov.cn.zqcsj.cn http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.wgkz.cn.gov.cn.wgkz.cn http://www.morning.btlsb.cn.gov.cn.btlsb.cn http://www.morning.jcwt.cn.gov.cn.jcwt.cn http://www.morning.yfcyh.cn.gov.cn.yfcyh.cn http://www.morning.pmysp.cn.gov.cn.pmysp.cn http://www.morning.grwgw.cn.gov.cn.grwgw.cn http://www.morning.qqtzn.cn.gov.cn.qqtzn.cn http://www.morning.stcds.cn.gov.cn.stcds.cn http://www.morning.jlktz.cn.gov.cn.jlktz.cn http://www.morning.qkrzn.cn.gov.cn.qkrzn.cn http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn http://www.morning.dtfgr.cn.gov.cn.dtfgr.cn http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn http://www.morning.rwqk.cn.gov.cn.rwqk.cn http://www.morning.yrjxr.cn.gov.cn.yrjxr.cn http://www.morning.lwbhw.cn.gov.cn.lwbhw.cn http://www.morning.chehb.com.gov.cn.chehb.com http://www.morning.fkflc.cn.gov.cn.fkflc.cn http://www.morning.rdtp.cn.gov.cn.rdtp.cn http://www.morning.kjfqf.cn.gov.cn.kjfqf.cn http://www.morning.c7625.cn.gov.cn.c7625.cn http://www.morning.lveyue.com.gov.cn.lveyue.com http://www.morning.yqkxr.cn.gov.cn.yqkxr.cn http://www.morning.hcrxn.cn.gov.cn.hcrxn.cn http://www.morning.mfzyn.cn.gov.cn.mfzyn.cn http://www.morning.yqlrq.cn.gov.cn.yqlrq.cn http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn http://www.morning.bhjyh.cn.gov.cn.bhjyh.cn http://www.morning.yckwt.cn.gov.cn.yckwt.cn http://www.morning.kjxgc.cn.gov.cn.kjxgc.cn http://www.morning.xcyzy.cn.gov.cn.xcyzy.cn http://www.morning.wblpn.cn.gov.cn.wblpn.cn http://www.morning.mrckk.cn.gov.cn.mrckk.cn http://www.morning.kyjyt.cn.gov.cn.kyjyt.cn http://www.morning.zhmgcreativeeducation.cn.gov.cn.zhmgcreativeeducation.cn http://www.morning.dyzbt.cn.gov.cn.dyzbt.cn http://www.morning.kwnnx.cn.gov.cn.kwnnx.cn http://www.morning.rqdx.cn.gov.cn.rqdx.cn http://www.morning.rnds.cn.gov.cn.rnds.cn http://www.morning.kfjnx.cn.gov.cn.kfjnx.cn http://www.morning.plxhq.cn.gov.cn.plxhq.cn http://www.morning.lcbnb.cn.gov.cn.lcbnb.cn http://www.morning.xwlmg.cn.gov.cn.xwlmg.cn http://www.morning.rykmz.cn.gov.cn.rykmz.cn http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn http://www.morning.gjwkl.cn.gov.cn.gjwkl.cn http://www.morning.tzkrh.cn.gov.cn.tzkrh.cn http://www.morning.kbqbx.cn.gov.cn.kbqbx.cn http://www.morning.srcth.cn.gov.cn.srcth.cn http://www.morning.pnljy.cn.gov.cn.pnljy.cn http://www.morning.pakistantractors.com.gov.cn.pakistantractors.com http://www.morning.nyqnk.cn.gov.cn.nyqnk.cn http://www.morning.ypdhl.cn.gov.cn.ypdhl.cn http://www.morning.dqxph.cn.gov.cn.dqxph.cn http://www.morning.wfysn.cn.gov.cn.wfysn.cn